/* ============================================================
   CRP DESIGN SYSTEM  —  assets/css/crp.css
   Clinical Research Encyclopedia / Tools
   ------------------------------------------------------------
   Direction: keep the CRP identity (navy #1e5a96, orange accent)
   and apply editorial discipline — flat panels, hairline rules,
   a real type scale, and motion that is deliberate rather than
   decorative.

   Why this file exists
   --------------------
   The previous UI had no single source of truth: 15 files each
   redefined `:root`, 14 PHP files carried their own <style>
   block, 264 distinct hex values shipped site-wide, and the
   token names had drifted away from their values
   (e.g. `--primary-burgundy: #ff7a3d`). Nothing could be read
   or reasoned about, so the result was arbitrary.

   Rules for this file
   -------------------
   1. ONE :root block. Every component below derives from it.
   2. Token names must describe their value. No legacy aliases.
   3. Colour, type, space, radius and shadow are finite scales.
   4. Transitions name properties. `transition: all` is banned.
   5. Nothing animates on page load. Motion is feedback only.
   6. Every interactive element has a visible :focus-visible ring.

   Load order:  crp.css  ->  crp-home.css (page layer)
   ============================================================ */

/* ── Fonts ───────────────────────────────────────────────────
   Self-hosted Latin variable fonts. The site runs on a .cn
   domain, so we do NOT depend on fonts.googleapis.com at
   runtime. Noto Sans SC (a Simplified-Chinese font, 15MB) is
   deliberately no longer used for English body copy.
   ------------------------------------------------------------ */
@font-face {
  font-family: 'Inter';
  src: url('/assets/fonts/crp/inter-latin-wght-normal.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Source Serif 4';
  src: url('/assets/fonts/crp/source-serif-4-latin-wght-normal.woff2') format('woff2');
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
}

/* ── Design tokens ───────────────────────────────────────── */
:root {
  /* Brand — unchanged identity */
  --brand:        #1e5a96;
  --brand-deep:   #0d3d66;
  --brand-soft:   #e8f2f9;

  /* Accent — now ONE role, not a competing surface colour */
  --accent:       #ff7a3d;
  --accent-deep:  #d85f1c;
  --accent-soft:  #fff0e7;

  /* Neutrals — cool ramp derived from the brand hue,
     replacing the borrowed Tailwind greys */
  --bg:           #f6f8fb;
  --surface:      #ffffff;
  --surface-2:    #eff3f8;
  --line:         #dbe3ec;
  --line-soft:    #eaeff5;
  --ink:          #14212e;
  --ink-dim:      #5a6b7b;
  --ink-mute:     #8797a7;

  /* Status — desaturated to sit beside the navy */
  --success:      #157a5a;
  --success-soft: #e6f3ed;
  --warning:      #8f6412;
  --warning-soft: #f9f1de;
  --danger:       #b3403c;
  --danger-soft:  #faeaea;
  --info:         #1e5a96;
  --info-soft:    #e8f2f9;

  /* Type */
  --font-sans:  'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI',
                Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --font-mono:  ui-monospace, 'SF Mono', 'Cascadia Mono', Menlo,
                Consolas, monospace;

  --fs-2xs:  0.6875rem;   /* 11 */
  --fs-xs:   0.75rem;     /* 12 */
  --fs-sm:   0.8125rem;   /* 13 */
  --fs-base: 0.9375rem;   /* 15 */
  --fs-md:   1rem;        /* 16 */
  --fs-lg:   1.125rem;    /* 18 */
  --fs-xl:   1.375rem;    /* 22 */
  --fs-2xl:  1.75rem;     /* 28 */
  --fs-3xl:  2.25rem;     /* 36 */
  --fs-4xl:  clamp(2.25rem, 1.4rem + 3vw, 3.25rem);

  --lh-tight: 1.15;
  --lh-snug:  1.3;
  --lh-body:  1.6;

  /* Space — 4px base */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.5rem;
  --sp-6: 2rem;
  --sp-7: 3rem;
  --sp-8: 4rem;
  --sp-9: 6rem;

  /* Radius — four values, nothing else */
  --r-sm:   4px;
  --r-md:   6px;
  --r-lg:   10px;
  --r-full: 999px;

  /* Shadow — navy-tinted, quiet, elevation only */
  --shadow-1: 0 1px 2px rgba(16, 33, 46, 0.06);
  --shadow-2: 0 2px 4px rgba(16, 33, 46, 0.05),
              0 10px 20px -10px rgba(16, 33, 46, 0.12);
  --shadow-3: 0 4px 8px rgba(16, 33, 46, 0.05),
              0 20px 36px -18px rgba(16, 33, 46, 0.16);

  /* Motion */
  --dur-fast: 120ms;
  --dur:      180ms;
  --ease:     cubic-bezier(0.2, 0, 0, 1);

  /* Layout */
  --wrap:    1120px;
  --measure: 68ch;

  /* Chrome sizing */
  --appbar-h:  56px;
  --sidebar-w: 248px;
  --control-h: 36px;

  /* Overlays & rings */
  --overlay:    rgba(13, 32, 48, 0.55);
  --focus-ring: 0 0 0 3px rgba(30, 90, 150, 0.15);

  color-scheme: light;
}

/* ── Dark mode ────────────────────────────────────────────────
   The token flip for the whole framework. An app opts in by
   having the `dark-mode` class on <html>; nothing here applies
   until it does, so an app that has not opted in is unaffected.

   The neutral ramp is Ant's own dark algorithm (the #141414
   family) rather than the Tailwind slate it replaced, and the
   brand keeps its light-mode #1e5a96 hue family instead of
   being re-tinted blue -- so dark mode reads as the same
   product, not a different theme.

   Proven in assets/apps/crk-chat/crk-chat.css, which is where
   this block lived before the lift. App-specific families
   (citation/cite/bg-primary-dark etc.) stay in that app file.

   The brand holds its light-mode hue; only the interactive
   steps lift for legibility on a dark ground (white-on-brand
   was 4.45:1, now 5.4:1).
   ─────────────────────────────────────────────────────────── */
.dark-mode {
  color-scheme: dark;

  --brand:       #2f6ea8;
  --brand-deep:  #3d80bd;
  --brand-soft:  #12293c;
  --accent:      #d4763f;
  --accent-soft: #2d1f14;

  --bg:        #141414;
  --surface:   #1f1f1f;
  --surface-2: #262626;
  --line:      #3d3d3d;
  --line-soft: #2b2b2b;
  --ink:       #f0f0f0;
  --ink-dim:   #c2c2c2;
  --ink-mute:  #9a9a9a;

  --success:      #4b9a2f;
  --success-soft: #16240f;
  --danger:       #d84a4a;
  --danger-soft:  #2a1414;
  --warning:      #c08a2e;
  --warning-soft: #2a2114;
  --info:         #4a86c4;
  --info-soft:    #12293c;

  --overlay:    rgba(0, 0, 0, 0.72);
  --focus-ring: 0 0 0 3px rgba(47, 110, 168, 0.45);

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.45);
  --shadow-2: 0 2px 4px rgba(0, 0, 0, 0.5), 0 10px 20px -10px rgba(0, 0, 0, 0.55);
  --shadow-3: 0 4px 8px rgba(0, 0, 0, 0.5), 0 20px 36px -18px rgba(0, 0, 0, 0.6);
}

/* Dark half only. The light half of this contrast override is an
   app concern today; adding it here would silently change light
   mode for high-contrast users across every app. */
@media (prefers-contrast: high) {
  .dark-mode { --line: var(--ink-dim); }
}

/* ── Baseline reset ──────────────────────────────────────────
   Josh Comeau-style modern reset: predictable sizing, media
   that cannot overflow, form controls that inherit type.
   Prose spacing is rebuilt explicitly rather than stripped.
   ------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }

body, h1, h2, h3, h4, h5, h6, p, figure, blockquote,
ul, ol, dl, dd, pre, fieldset, hr { margin: 0; }

ul[role='list'], ol[role='list'] { list-style: none; padding: 0; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

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

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

p, li, dd, figcaption { overflow-wrap: break-word; }
h1, h2, h3, h4, h5, h6 { overflow-wrap: break-word; }

/* Prose rhythm — pages keep breathing room by default */
p, blockquote, figure, ul, ol, dl, pre { margin-block: 0 var(--sp-4); }
h1, h2, h3, h4, h5, h6 { margin-block: 0 0.5em; }

/* ── Base ────────────────────────────────────────────────── */
body {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv05' 1, 'cv08' 1, 'tnum' 0;
  text-rendering: optimizeLegibility;
}

/* ── Focus — non-negotiable ──────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
:focus:not(:focus-visible) { outline: none; }

/* ── Typography ──────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  line-height: var(--lh-tight);
  letter-spacing: -0.015em;
  font-weight: 600;
  color: var(--ink);
  text-wrap: balance;
}
h1 { font-size: var(--fs-4xl); font-weight: 700; letter-spacing: -0.025em; }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-lg); letter-spacing: -0.01em; }
h4 { font-size: var(--fs-md); letter-spacing: 0; }

p { text-wrap: pretty; }

/* Display face — serif, used for statement headlines only */
.display {
  font-family: var(--font-serif);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: var(--lh-tight);
}

/* Micro-label. The editorial "masthead" marker. */
.kicker {
  display: inline-block;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brand);
}

.lede {
  font-size: var(--fs-lg);
  line-height: var(--lh-snug);
  color: var(--ink-dim);
  max-width: var(--measure);
}

.muted   { color: var(--ink-dim); }
.mono    { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ── Links ───────────────────────────────────────────────── */
a {
  color: var(--brand);
  text-decoration: none;
  transition: color var(--dur-fast) var(--ease);
}
a:hover {
  color: var(--brand-deep);
  text-decoration: underline;
  text-underline-offset: 0.25em;
  text-decoration-thickness: 1px;
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 0.625rem 1.125rem;
  font-size: var(--fs-sm);
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.2;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease);
}
.btn:hover { text-decoration: none; }

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.btn-primary:hover { background: var(--brand-deep); border-color: var(--brand-deep); color: #fff; }

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-accent:hover { background: var(--accent-deep); border-color: var(--accent-deep); color: #fff; }

.btn-outline {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}
.btn-outline:hover { background: var(--surface); border-color: var(--brand); color: var(--brand); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--brand);
  padding-inline: 0.5rem;
}
.btn-ghost:hover { color: var(--brand-deep); text-decoration: underline; text-underline-offset: 0.25em; }

.btn-lg { padding: 0.8125rem 1.5rem; font-size: var(--fs-base); }

/* ── Panels / cards ──────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  transition: border-color var(--dur) var(--ease),
              box-shadow var(--dur) var(--ease),
              transform var(--dur) var(--ease);
}
.card-interactive:hover {
  border-color: #c3d2e0;
  box-shadow: var(--shadow-2);
  transform: translateY(-2px);
}

/* ── Tags ────────────────────────────────────────────────── */
.tag {
  display: inline-block;
  padding: 0.1875rem 0.5rem;
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: var(--r-sm);
  background: var(--brand-soft);
  color: var(--brand);
}
.tag-accent { background: var(--accent-soft); color: var(--accent-deep); }

/* ── Forms ───────────────────────────────────────────────── */
input[type='text'],
input[type='email'],
input[type='search'],
textarea,
select {
  width: 100%;
  padding: 0.5625rem 0.75rem;
  font-size: var(--fs-base);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  transition: border-color var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease);
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(30, 90, 150, 0.15);
}

/* ── Layout utilities ────────────────────────────────────── */
.wrap {
  width: 100%;
  max-width: var(--wrap);
  margin-inline: auto;
  padding-inline: var(--sp-5);
}

.divider {
  border: 0;
  border-top: 1px solid var(--line);
  margin-block: var(--sp-7);
}

.shadow-1 { box-shadow: var(--shadow-1); }
.shadow-2 { box-shadow: var(--shadow-2); }
.shadow-3 { box-shadow: var(--shadow-3); }

.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;
}

/* ============================================================
   COMPONENT LIBRARY
   ------------------------------------------------------------
   Class names are taken from the vocabulary the apps already
   use (admin, crk-chat, QnA, qmp, pmp, iwa). The goal is that
   an app can adopt the design system by swapping its
   stylesheet link, without rewriting markup.

   Everything below is additive. Nothing here redefines a token.
   ============================================================ */

/* ── App shell ───────────────────────────────────────────── */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100dvh;
}
.shell.is-collapsed { grid-template-columns: 0 minmax(0, 1fr); }

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  height: 100dvh;
  position: sticky;
  top: 0;
  align-self: start;
  overflow: hidden;
}
.sidebar-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--line);
  min-height: var(--appbar-h);
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--ink);
}
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar-section {
  padding: var(--sp-4) var(--sp-3) var(--sp-1);
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-mute);
}
.sidebar-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0.5rem var(--sp-3);
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--ink-dim);
  transition: background-color var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease);
}
.sidebar-item:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.sidebar-item.is-active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.sidebar-item .icon { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-item .count {
  margin-left: auto;
  font-size: var(--fs-2xs);
  font-weight: 600;
  color: var(--ink-mute);
}
.sidebar-footer {
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--line);
}

/* ── Appbar / top nav ────────────────────────────────────── */
.appbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  min-height: var(--appbar-h);
  padding-inline: var(--sp-5);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--line);
}
.appbar-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--ink);
}
.appbar-brand .logo { height: 30px; width: auto; }
.appbar-spacer { flex: 1; }
.appbar-actions { display: flex; align-items: center; gap: var(--sp-2); }

/* ── Breadcrumb ──────────────────────────────────────────── */
.breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-2);
  font-size: var(--fs-sm);
  color: var(--ink-mute);
}
.breadcrumb a { color: var(--ink-dim); }
.breadcrumb-item.is-current { color: var(--ink); font-weight: 500; }
.breadcrumb-sep { color: var(--line); user-select: none; }

/* ── Tabs ────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: var(--sp-1);
  border-bottom: 1px solid var(--line);
  margin-bottom: var(--sp-5);
  overflow-x: auto;
}
.tab {
  padding: 0.625rem var(--sp-4);
  margin-bottom: -1px;
  font-size: var(--fs-sm);
  font-weight: 500;
  white-space: nowrap;
  color: var(--ink-dim);
  border-bottom: 2px solid transparent;
  transition: color var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease);
}
.tab:hover { color: var(--ink); text-decoration: none; }
.tab.is-active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

/* ── Step indicator ──────────────────────────────────────── */
.steps {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
}
.step { display: flex; align-items: center; gap: var(--sp-3); }
.step-dot {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--ink-mute);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--r-full);
}
.step.is-active .step-dot { color: #fff; background: var(--brand); border-color: var(--brand); }
.step.is-done .step-dot { color: #fff; background: var(--success); border-color: var(--success); }
.step-title { font-size: var(--fs-sm); font-weight: 600; color: var(--ink); }
.step-desc { font-size: var(--fs-xs); color: var(--ink-mute); }
.step-line { flex: 1; height: 1px; min-width: var(--sp-4); background: var(--line); }

/* ── Page content ────────────────────────────────────────── */
.content-body { padding: var(--sp-6) var(--sp-6) var(--sp-8); }
.content-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
}
.page-title { font-size: var(--fs-xl); font-weight: 600; letter-spacing: -0.02em; }
.page-sub { margin-top: 2px; font-size: var(--fs-sm); color: var(--ink-dim); }

/* ── Footer ──────────────────────────────────────────────── */
.footer {
  padding: var(--sp-5);
  color: var(--ink-mute);
  font-size: var(--fs-sm);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.footer-inner {
  max-width: var(--wrap);
  margin-inline: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-4);
}

/* ── Cards ───────────────────────────────────────────────── */
.card-header {
  padding: var(--sp-5);
  border-bottom: 1px solid var(--line-soft);
}
.card-title { font-size: var(--fs-md); font-weight: 600; color: var(--ink); letter-spacing: -0.005em; }
.card-subtitle { margin-top: 2px; font-size: var(--fs-sm); color: var(--ink-dim); }
.card-body { padding: var(--sp-5); }
.card-footer {
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}
.card-actions { margin-left: auto; display: flex; align-items: center; gap: var(--sp-2); }
.card-icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: var(--r-md);
  background: var(--brand-soft);
  color: var(--brand);
}
.card-icon svg { width: 20px; height: 20px; }
.card-media {
  aspect-ratio: 16 / 9;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line-soft);
  overflow: hidden;
}
.card-media img { width: 100%; height: 100%; object-fit: cover; }

/* ── Stat blocks ─────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--sp-4);
}
.stat {
  padding: var(--sp-5);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
.stat-label {
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-mute);
}
.stat-value {
  margin-top: var(--sp-2);
  font-size: var(--fs-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.stat-delta { margin-top: var(--sp-1); font-size: var(--fs-sm); font-weight: 500; }
.stat-delta.is-up { color: var(--success); }
.stat-delta.is-down { color: var(--danger); }

/* ── Badges ──────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.1875rem 0.5rem;
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1.4;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--ink-dim);
  white-space: nowrap;
}
.badge-primary { background: var(--brand-soft); color: var(--brand); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); }
.badge-info    { background: var(--info-soft);    color: var(--info); }
.badge-muted   { background: var(--surface-2);    color: var(--ink-mute); }
.badge-lg { padding: 0.3125rem 0.75rem; font-size: var(--fs-xs); }

/* ── Chips (state pills) ─────────────────────────────────── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0.25rem 0.75rem;
  font-size: var(--fs-xs);
  font-weight: 500;
  border-radius: var(--r-full);
  background: var(--surface-2);
  color: var(--ink-dim);
  border: 1px solid transparent;
}
.chip-completed { background: var(--success-soft); color: var(--success); }
.chip-generating { background: var(--brand-soft); color: var(--brand); }
.chip-pending { background: var(--surface-2); color: var(--ink-mute); }
.chip-error { background: var(--danger-soft); color: var(--danger); }

/* ── Status dot ──────────────────────────────────────────── */
.status {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-sm);
  color: var(--ink-dim);
}
.status::before {
  content: '';
  width: 7px;
  height: 7px;
  flex-shrink: 0;
  border-radius: var(--r-full);
  background: var(--ink-mute);
}
.status.is-online::before  { background: var(--success); }
.status.is-busy::before    { background: var(--warning); }
.status.is-offline::before { background: var(--ink-mute); }
.status.is-error::before   { background: var(--danger); }

/* ── Button variants ─────────────────────────────────────── */
.btn-secondary {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
}
.btn-secondary:hover { background: var(--surface-2); border-color: #c3d2e0; color: var(--ink); }

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: #953330; border-color: #953330; color: #fff; }

.btn-success {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}
.btn-success:hover { background: #106048; border-color: #106048; color: #fff; }

.btn-warning {
  background: var(--warning);
  border-color: var(--warning);
  color: #fff;
}
.btn-warning:hover { background: #75520e; border-color: #75520e; color: #fff; }

.btn-sm { padding: 0.375rem 0.75rem; font-size: var(--fs-xs); }
.btn-icon { padding: 0; width: var(--control-h); height: var(--control-h); }
.btn-icon.btn-sm { width: 30px; height: 30px; }
.btn-block { width: 100%; }

.btn:disabled,
.btn.is-disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}
.btn.is-loading { color: transparent; position: relative; }
.btn.is-loading::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: var(--r-full);
  color: #fff;
  animation: crp-spin 0.6s linear infinite;
}

/* ── Forms ───────────────────────────────────────────────── */
.form-group { margin-bottom: var(--sp-4); }
.form-label {
  display: block;
  margin-bottom: var(--sp-2);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--ink);
}
.form-label .req { color: var(--danger); margin-left: 2px; }
.form-hint { margin-top: var(--sp-1); font-size: var(--fs-xs); color: var(--ink-mute); }
.form-error { margin-top: var(--sp-1); font-size: var(--fs-xs); color: var(--danger); }
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--sp-4);
}
.form-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-top: var(--sp-5);
}
.fieldset {
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  margin-bottom: var(--sp-5);
}
.legend {
  padding-inline: var(--sp-2);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ink);
}
.has-error .input,
.has-error .select,
.has-error .textarea { border-color: var(--danger); }
.has-error .input:focus { box-shadow: 0 0 0 3px rgba(179, 64, 60, 0.15); }

.input,
.select,
.textarea {
  width: 100%;
  padding: 0.5625rem 0.75rem;
  font-size: var(--fs-base);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  transition: border-color var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease);
}
.input:hover, .select:hover, .textarea:hover { border-color: #c3d2e0; }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--focus-ring);
}
.input::placeholder, .textarea::placeholder { color: var(--ink-mute); }
.textarea { min-height: 96px; resize: vertical; line-height: 1.55; }
.select { appearance: none; padding-right: 2.25rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4.5L6 8.5L10 4.5' fill='none' stroke='%235a6b7b' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
}

.input-group { display: flex; align-items: stretch; }
.input-group .input { border-radius: 0; }
.input-group > :first-child { border-top-left-radius: var(--r-md); border-bottom-left-radius: var(--r-md); }
.input-group > :last-child  { border-top-right-radius: var(--r-md); border-bottom-right-radius: var(--r-md); }
.input-addon {
  display: flex;
  align-items: center;
  padding-inline: var(--sp-3);
  font-size: var(--fs-sm);
  color: var(--ink-dim);
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.checkbox, .radio {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-sm);
  color: var(--ink);
  cursor: pointer;
}
.checkbox input, .radio input {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  accent-color: var(--brand);
  cursor: pointer;
}
.radio-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: var(--sp-2);
}
.radio-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-sm);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease),
              background-color var(--dur-fast) var(--ease);
}
.radio-item:hover { border-color: #c3d2e0; }
.radio-item:has(input:checked) {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 600;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: var(--fs-sm);
  color: var(--ink);
  cursor: pointer;
}
.switch input { position: absolute; width: 0; height: 0; opacity: 0; }
.switch-track {
  position: relative;
  width: 38px;
  height: 22px;
  flex-shrink: 0;
  border-radius: var(--r-full);
  background: var(--line);
  transition: background-color var(--dur) var(--ease);
}
.switch-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: var(--r-full);
  background: #fff;
  box-shadow: var(--shadow-1);
  transition: transform var(--dur) var(--ease);
}
.switch input:checked + .switch-track { background: var(--brand); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--brand); outline-offset: 2px; }

.upload-zone {
  padding: var(--sp-6);
  text-align: center;
  color: var(--ink-dim);
  background: var(--surface);
  border: 1.5px dashed var(--line);
  border-radius: var(--r-lg);
  transition: border-color var(--dur) var(--ease),
              background-color var(--dur) var(--ease);
}
.upload-zone:hover,
.upload-zone.is-dragover { border-color: var(--brand); background: var(--brand-soft); }
.upload-icon { width: 40px; height: 40px; margin: 0 auto var(--sp-3); color: var(--brand); }
.upload-title { font-size: var(--fs-base); font-weight: 600; color: var(--ink); }
.upload-hint { margin-top: var(--sp-1); font-size: var(--fs-xs); color: var(--ink-mute); }

/* ── Alerts ──────────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-4);
  font-size: var(--fs-sm);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
.alert-icon { flex-shrink: 0; width: 20px; height: 20px; color: var(--ink-mute); }
.alert-body { flex: 1; min-width: 0; }
.alert-title { font-weight: 600; }
.alert-text { margin-top: 2px; color: var(--ink-dim); }
.alert-close {
  flex-shrink: 0;
  margin-left: auto;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-mute);
  cursor: pointer;
}
.alert-close:hover { background: rgba(0, 0, 0, 0.05); color: var(--ink); }

.alert-info    { background: var(--info-soft);    border-color: #cfe1f0; }
.alert-info    .alert-icon { color: var(--info); }
.alert-success { background: var(--success-soft); border-color: #cbe6da; }
.alert-success .alert-icon { color: var(--success); }
.alert-warning { background: var(--warning-soft); border-color: #efdfb8; }
.alert-warning .alert-icon { color: var(--warning); }
.alert-danger  { background: var(--danger-soft);  border-color: #f0cfce; }
.alert-danger  .alert-icon { color: var(--danger); }

/* ── Toasts ──────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  right: var(--sp-5);
  bottom: var(--sp-5);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  width: min(360px, calc(100vw - 2 * var(--sp-5)));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-4);
  font-size: var(--fs-sm);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--brand);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-3);
  pointer-events: auto;
}
.toast-icon { flex-shrink: 0; width: 18px; height: 18px; color: var(--brand); }
.toast-success { border-left-color: var(--success); }
.toast-success .toast-icon { color: var(--success); }
.toast-warning { border-left-color: var(--warning); }
.toast-warning .toast-icon { color: var(--warning); }
.toast-danger { border-left-color: var(--danger); }
.toast-danger .toast-icon { color: var(--danger); }
.toast-body { flex: 1; min-width: 0; }
.toast-title { font-weight: 600; }
.toast-text { margin-top: 2px; color: var(--ink-dim); }
.toast-close {
  flex-shrink: 0;
  border: 0;
  background: transparent;
  color: var(--ink-mute);
  cursor: pointer;
  line-height: 1;
}

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: grid;
  place-items: center;
  padding: var(--sp-5);
  background: var(--overlay);
}
.modal {
  width: 100%;
  max-width: 520px;
  max-height: calc(100dvh - 2 * var(--sp-5));
  overflow: auto;
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-3);
}
.modal-lg { max-width: 760px; }
.modal-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-5);
  border-bottom: 1px solid var(--line-soft);
}
.modal-title { font-size: var(--fs-lg); font-weight: 600; letter-spacing: -0.01em; }
.modal-close {
  margin-left: auto;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  font-size: 1.25rem;
  line-height: 1;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-mute);
  cursor: pointer;
}
.modal-close:hover { background: var(--surface-2); color: var(--ink); }
.modal-body { padding: var(--sp-5); }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--line-soft);
}

/* ── Dropdown ────────────────────────────────────────────── */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 60;
  min-width: 190px;
  padding: var(--sp-1);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-3);
}
.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  padding: 0.5rem var(--sp-3);
  font-size: var(--fs-sm);
  color: var(--ink-dim);
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: var(--r-sm);
  cursor: pointer;
}
.dropdown-item:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.dropdown-item.is-danger { color: var(--danger); }
.dropdown-item.is-danger:hover { background: var(--danger-soft); }
.dropdown-sep { height: 1px; margin: var(--sp-1) 0; background: var(--line-soft); }

/* ── Tooltip ─────────────────────────────────────────────── */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 70;
  padding: 0.25rem 0.5rem;
  font-size: var(--fs-2xs);
  font-weight: 500;
  white-space: nowrap;
  color: #fff;
  background: var(--ink);
  border-radius: var(--r-sm);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease);
}
[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after { opacity: 1; }

/* ── Tables ──────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
.data-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.data-table th {
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: left;
  white-space: nowrap;
  color: var(--ink-mute);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
.data-table td {
  padding: var(--sp-3) var(--sp-4);
  color: var(--ink);
  vertical-align: middle;
  border-bottom: 1px solid var(--line-soft);
}
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Key / value list ────────────────────────────────────── */
.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--sp-2) var(--sp-4);
  margin: 0;
  font-size: var(--fs-sm);
}
.kv dt { color: var(--ink-mute); }
.kv dd { margin: 0; color: var(--ink); font-weight: 500; }

/* ── Pagination ──────────────────────────────────────────── */
.pagination { display: flex; align-items: center; gap: var(--sp-1); }
.page-link {
  min-width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding-inline: var(--sp-2);
  font-size: var(--fs-sm);
  color: var(--ink-dim);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
}
.page-link:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.page-link.is-active { background: var(--brand); color: #fff; }
.page-link:disabled { opacity: 0.45; pointer-events: none; }

/* ── Progress ────────────────────────────────────────────── */
.progress {
  width: 100%;
  height: 6px;
  background: var(--surface-2);
  border-radius: var(--r-full);
  overflow: hidden;
}
.progress-sm { height: 4px; }
.progress-bar {
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
  transition: width var(--dur) var(--ease);
}
.progress-bar.is-success { background: var(--success); }
.progress-bar.is-warning { background: var(--warning); }
.progress-bar.is-danger  { background: var(--danger); }
.progress-head {
  display: flex;
  justify-content: space-between;
  margin-bottom: var(--sp-1);
  font-size: var(--fs-xs);
  color: var(--ink-mute);
}

/* ── Spinners & skeletons ────────────────────────────────── */
@keyframes crp-spin { to { transform: rotate(360deg); } }
@keyframes crp-shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
@keyframes crp-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  color: var(--brand);
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: var(--r-full);
  animation: crp-spin 0.6s linear infinite;
}
.spinner-lg { width: 28px; height: 28px; border-width: 3px; }
.spinner-sm { width: 12px; height: 12px; }
.spinner-block { display: grid; place-items: center; padding: var(--sp-8); }

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, #e5ebf2 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  border-radius: var(--r-sm);
  animation: crp-shimmer 1.4s ease infinite;
}
.skeleton-text { height: 12px; margin-bottom: var(--sp-2); }
.skeleton-title { width: 45%; height: 18px; margin-bottom: var(--sp-3); }
.skeleton-line { height: 10px; }
.skeleton-card { height: 120px; border-radius: var(--r-lg); }
.skeleton-avatar { width: 32px; height: 32px; border-radius: var(--r-full); }

.dots { display: inline-flex; gap: 3px; align-items: center; }
.dots span {
  width: 5px;
  height: 5px;
  border-radius: var(--r-full);
  background: currentColor;
  animation: crp-pulse 1.2s ease-in-out infinite;
}
.dots span:nth-child(2) { animation-delay: 0.15s; }
.dots span:nth-child(3) { animation-delay: 0.3s; }

/* ── Empty state ─────────────────────────────────────────── */
.empty-state {
  padding: var(--sp-9) var(--sp-5);
  text-align: center;
  color: var(--ink-dim);
}
.empty-icon { width: 44px; height: 44px; margin: 0 auto var(--sp-4); color: var(--ink-mute); }
.empty-title { font-size: var(--fs-md); font-weight: 600; color: var(--ink); }
.empty-text { margin-top: var(--sp-1); font-size: var(--fs-sm); }

/* ── Avatars ─────────────────────────────────────────────── */
.avatar {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--brand);
  background: var(--brand-soft);
  border-radius: var(--r-full);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 24px; height: 24px; font-size: var(--fs-2xs); }
.avatar-lg { width: 44px; height: 44px; font-size: var(--fs-base); }
.avatar-group { display: flex; }
.avatar-group .avatar + .avatar { margin-left: -8px; box-shadow: 0 0 0 2px var(--surface); }

/* ── Chat ────────────────────────────────────────────────── */
.chat { display: flex; flex-direction: column; gap: var(--sp-5); }
.msg-row { display: flex; align-items: flex-start; gap: var(--sp-3); }
.msg-row.is-user { flex-direction: row-reverse; }
.msg-bubble {
  max-width: 620px;
  padding: var(--sp-4) var(--sp-5);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  border-radius: var(--r-lg);
}
.msg-row.is-assistant .msg-bubble {
  background: var(--surface);
  border: 1px solid var(--line);
  border-top-left-radius: var(--r-sm);
}
.msg-row.is-user .msg-bubble {
  background: var(--brand);
  color: #fff;
  border-top-right-radius: var(--r-sm);
}
.msg-meta {
  display: flex;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
  font-size: var(--fs-2xs);
  color: var(--ink-mute);
}
.msg-row.is-user .msg-meta { justify-content: flex-end; }
.msg-citations {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: var(--sp-3);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--line-soft);
}
.cite {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 2px 8px;
  font-size: var(--fs-2xs);
  color: var(--ink-dim);
  background: var(--surface-2);
  border-radius: var(--r-full);
}
.composer {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
.composer .textarea { min-height: 40px; border: 0; padding: var(--sp-2); }
.composer .textarea:focus { box-shadow: none; }
.followups { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.followup {
  padding: 0.375rem 0.75rem;
  font-size: var(--fs-xs);
  color: var(--brand);
  background: var(--brand-soft);
  border-radius: var(--r-full);
}
.followup:hover { color: #fff; background: var(--brand); text-decoration: none; }

/* ── Knowledge-base cards ────────────────────────────────── */
.kb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--sp-4);
}
.kb-card {
  display: flex;
  flex-direction: column;
  padding: var(--sp-5);
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  transition: border-color var(--dur) var(--ease),
              box-shadow var(--dur) var(--ease);
}
.kb-card:hover {
  color: inherit;
  text-decoration: none;
  border-color: #c3d2e0;
  box-shadow: var(--shadow-2);
}
.kb-icon {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-bottom: var(--sp-4);
  background: var(--surface-2);
  border-radius: var(--r-md);
}
.kb-icon img { width: 28px; height: 28px; object-fit: contain; }
.kb-title { font-size: var(--fs-base); font-weight: 600; color: var(--ink); }
.kb-desc { margin-top: var(--sp-1); margin-bottom: var(--sp-4); flex-grow: 1; font-size: var(--fs-sm); color: var(--ink-dim); }
.kb-cta {
  align-self: flex-start;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--brand);
}

/* ── Code ────────────────────────────────────────────────── */
.code-block { overflow: hidden; background: #0f1b26; border-radius: var(--r-md); }
.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem var(--sp-4);
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  color: #8797a7;
  background: rgba(255, 255, 255, 0.06);
}
.code-block pre { margin: 0; padding: var(--sp-4); overflow-x: auto; }
.code-block code,
.code-inline {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  line-height: 1.6;
  color: #dbe3ec;
}
.code-inline {
  padding: 0.12em 0.4em;
  font-size: 0.9em;
  color: var(--ink);
  background: var(--surface-2);
  border-radius: var(--r-sm);
}

/* ── Log viewer ──────────────────────────────────────────── */
.log {
  max-height: 280px;
  overflow: auto;
  padding: var(--sp-4);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  line-height: 1.7;
  color: #c7d2de;
  background: #0f1b26;
  border-radius: var(--r-md);
}
.log-line { display: flex; gap: var(--sp-3); white-space: pre; }
.log-num { min-width: 2.5ch; text-align: right; color: #5a6b7b; user-select: none; }
.log-warn { color: #e0b155; }
.log-err  { color: #e08a86; }
.log-ok   { color: #7fc7a6; }

/* ── Accordion (details/summary) ─────────────────────────── */
.accordion { overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.accordion-item + .accordion-item { border-top: 1px solid var(--line-soft); }
.accordion-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  list-style: none;
}
.accordion-header::-webkit-details-marker { display: none; }
.accordion-header:hover { background: var(--surface-2); }
.accordion-chevron { margin-left: auto; color: var(--ink-mute); transition: transform var(--dur) var(--ease); }
details[open] .accordion-chevron { transform: rotate(90deg); }
.accordion-body { padding: 0 var(--sp-5) var(--sp-4); font-size: var(--fs-sm); color: var(--ink-dim); }

/* ── Table of contents ───────────────────────────────────── */
.toc { display: flex; flex-direction: column; gap: 2px; font-size: var(--fs-sm); border-left: 1px solid var(--line); }
.toc-item {
  margin-left: -1px;
  padding: 0.25rem var(--sp-4);
  color: var(--ink-dim);
  border-left: 2px solid transparent;
}
.toc-item:hover { color: var(--ink); text-decoration: none; }
.toc-item.is-active { color: var(--brand); font-weight: 600; border-left-color: var(--brand); }
.toc-sub { padding-left: var(--sp-7); font-size: var(--fs-xs); }

/* ── Prose ───────────────────────────────────────────────── */
.prose { max-width: var(--measure); font-size: var(--fs-base); line-height: var(--lh-body); color: var(--ink); }
.prose h2 { margin-top: var(--sp-6); font-size: var(--fs-xl); }
.prose h3 { margin-top: var(--sp-5); font-size: var(--fs-lg); }
.prose ul, .prose ol { margin-bottom: var(--sp-4); padding-left: 1.25rem; }
.prose li { margin-bottom: var(--sp-2); }
.prose blockquote {
  margin-bottom: var(--sp-4);
  padding-left: var(--sp-4);
  font-style: italic;
  color: var(--ink-dim);
  border-left: 3px solid var(--brand);
}

/* ── Utilities ───────────────────────────────────────────── */
.stack > * + * { margin-top: var(--sp-4); }
.stack-sm > * + * { margin-top: var(--sp-2); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3); }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1 { flex: 1; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: var(--sp-4); }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--sp-4); }
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--sp-4); }
.gap-2 { gap: var(--sp-2); }
.gap-4 { gap: var(--sp-4); }
.mt-2 { margin-top: var(--sp-2); }
.mt-4 { margin-top: var(--sp-4); }
.mt-6 { margin-top: var(--sp-6); }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: var(--sp-2); }
.mb-4 { margin-bottom: var(--sp-4); }
.mb-6 { margin-bottom: var(--sp-6); }
.w-full { width: 100%; }
.hidden { display: none; }
.text-center { text-align: center; }
.text-muted { color: var(--ink-dim); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.kbd {
  padding: 0.1rem 0.35rem;
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  color: var(--ink-dim);
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: var(--r-sm);
}

/* ── Icons (inline SVG sprite) ───────────────────────────── */
.icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  /* The `svg { max-width: 100% }` reset above would otherwise clamp a fixed-size
     icon to its container's content box (0px inside a padded button), so an
     icon-only button renders blank. Icons are fixed-size by contract. */
  max-width: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-sm { width: 15px; height: 15px; }
.icon-lg { width: 22px; height: 22px; }

/* ── Motion hygiene ──────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
