/* ==========================================================================
   Research UI core — shared design system for the five portfolio projects.
   Canonical copy lives in AI_ML_PROJECTS/_design_system/core.css and is
   copied into each project's static/css/ by _design_system/sync.sh.
   Edit here, then run sync.sh. Project identity lives in static/css/app.css,
   which overrides the tokens below.
   ========================================================================== */

:root {
  /* Typography */
  --font-sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font-display: var(--font-sans);

  --fs-2xs: 11px;
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-base: 15px;
  --fs-md: 17px;
  --fs-lg: 20px;
  --fs-xl: 26px;
  --fs-2xl: 32px;
  --lh-tight: 1.25;
  --lh-base: 1.55;

  /* Spacing scale (4px base) */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px; --sp-5: 20px;
  --sp-6: 24px; --sp-7: 32px; --sp-8: 40px; --sp-9: 56px; --sp-10: 72px;

  /* Shape */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --container: 1240px;

  /* Neutral light palette (projects override) */
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f2f2ef;
  --surface-3: #e9e9e4;
  --border: #e1e0da;
  --border-strong: #c9c8c0;
  --text: #1c1f24;
  --text-muted: #565b66;
  --text-faint: #8a8f99;

  --accent: #1f3a5f;
  --accent-hover: #172d4a;
  --accent-ink: #ffffff;
  --accent-soft: #e7edf5;

  --ok: #1d7a4c;      --ok-soft: #e4f3ea;
  --warn: #9a6200;    --warn-soft: #fbf1dc;
  --err: #b42318;     --err-soft: #fdeceb;
  --info: #1f5fa8;    --info-soft: #e7f0fa;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.07), 0 1px 3px rgba(16, 24, 40, 0.05);
  --focus: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);

  --header-h: 56px;
  color-scheme: light;
}

/* -------------------------------------------------------------------------- */
/* Base                                                                       */
/* -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--header-h) + 16px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0; line-height: var(--lh-tight); font-weight: 600; color: var(--text); }
p { margin: 0; }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
code, kbd, pre, samp { font-family: var(--font-mono); font-size: 0.92em; }
img, svg { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-sm); }
::selection { background: color-mix(in srgb, var(--accent) 22%, transparent); }
[hidden] { display: none !important; }
.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: absolute; left: var(--sp-4); top: -48px; z-index: 100;
  background: var(--accent); color: var(--accent-ink); padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-md); text-decoration: none; transition: top .15s;
}
.skip-link:focus { top: var(--sp-2); color: var(--accent-ink); }
.mono { font-family: var(--font-mono); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.nowrap { white-space: nowrap; }

/* -------------------------------------------------------------------------- */
/* Layout                                                                     */
/* -------------------------------------------------------------------------- */
.container { width: 100%; max-width: var(--container); margin: 0 auto; padding: 0 var(--sp-6); }
@media (max-width: 640px) { .container { padding: 0 var(--sp-4); } }

.stack > * + * { margin-top: var(--sp-4); }
.stack-sm > * + * { margin-top: var(--sp-2); }
.stack-lg > * + * { margin-top: var(--sp-6); }
.row { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; }
.grid { display: grid; gap: var(--sp-5); }
.grid-2 { display: grid; gap: var(--sp-5); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { display: grid; gap: var(--sp-5); grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { display: grid; gap: var(--sp-4); grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 960px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 720px) { .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); } }
@media (max-width: 360px) { .grid-4 { grid-template-columns: minmax(0, 1fr); } }

/* -------------------------------------------------------------------------- */
/* App header                                                                 */
/* -------------------------------------------------------------------------- */
.app-header {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  -webkit-backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
.app-header .container { display: flex; align-items: center; gap: var(--sp-5); min-height: var(--header-h); }
.brand { display: flex; align-items: center; gap: var(--sp-3); text-decoration: none; color: var(--text); min-width: 0; }
.brand:hover { color: var(--text); }
.brand-mark { width: 26px; height: 26px; flex: none; color: var(--accent); }
.brand-name { font-weight: 600; font-size: var(--fs-base); letter-spacing: -0.01em; white-space: nowrap; }
.brand-sub { font-size: var(--fs-xs); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-nav { display: flex; gap: var(--sp-1); margin-left: auto; }
.header-nav a {
  font-size: var(--fs-sm); color: var(--text-muted); text-decoration: none;
  padding: 6px 10px; border-radius: var(--radius-md);
}
.header-nav a:hover { color: var(--text); background: var(--surface-2); }
.header-nav a[aria-current="true"] { color: var(--text); background: var(--surface-2); }
.header-status { margin-left: var(--sp-2); }
.nav-toggle { display: none; }
@media (max-width: 860px) {
  .brand-sub { display: none; }
  .nav-toggle {
    display: inline-flex; margin-left: auto; align-items: center; justify-content: center;
    width: 36px; height: 36px; border: 1px solid var(--border); border-radius: var(--radius-md);
    background: var(--surface); cursor: pointer;
  }
  .header-nav {
    display: none; position: absolute; top: 100%; left: 0; right: 0; margin: 0;
    flex-direction: column; padding: var(--sp-2) var(--sp-4) var(--sp-4);
    background: var(--bg); border-bottom: 1px solid var(--border); box-shadow: var(--shadow-md);
  }
  .header-nav.is-open { display: flex; }
  .header-nav a { padding: 10px 12px; font-size: var(--fs-base); }
  .header-status .status-text { display: none; }
}

/* -------------------------------------------------------------------------- */
/* Page intro                                                                 */
/* -------------------------------------------------------------------------- */
.page-intro { padding: var(--sp-8) 0 var(--sp-6); }
.eyebrow {
  font-family: var(--font-mono); font-size: var(--fs-2xs); font-weight: 500;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted);
}
.page-title {
  font-family: var(--font-display); font-size: var(--fs-2xl); font-weight: 600;
  letter-spacing: -0.02em; margin-top: var(--sp-2); max-width: 30ch;
}
.page-lede { margin-top: var(--sp-3); color: var(--text-muted); font-size: var(--fs-md); max-width: 72ch; }
.meta-row { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-5); margin-top: var(--sp-4); font-size: var(--fs-sm); color: var(--text-muted); }
.meta-row strong { color: var(--text); font-weight: 500; }
@media (max-width: 640px) {
  .page-intro { padding: var(--sp-6) 0 var(--sp-4); }
  .page-title { font-size: var(--fs-xl); }
  .page-lede { font-size: var(--fs-base); }
}

/* -------------------------------------------------------------------------- */
/* Sections & panels                                                          */
/* -------------------------------------------------------------------------- */
.section { padding: var(--sp-6) 0; }
.section + .section { border-top: 1px solid var(--border); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; margin-bottom: var(--sp-5); }
.section-title { font-size: var(--fs-lg); letter-spacing: -0.01em; }
.section-desc { color: var(--text-muted); font-size: var(--fs-sm); max-width: 70ch; margin-top: var(--sp-1); }

.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); min-width: 0;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.panel-title { font-size: var(--fs-base); font-weight: 600; }
.panel-sub { font-size: var(--fs-xs); color: var(--text-muted); }
.panel-body { padding: var(--sp-5); }
.panel-foot { padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--border); font-size: var(--fs-xs); color: var(--text-muted); }
.panel-flush .panel-body { padding: 0; }
@media (max-width: 640px) {
  .panel-head, .panel-body { padding-left: var(--sp-4); padding-right: var(--sp-4); }
}

/* -------------------------------------------------------------------------- */
/* Buttons                                                                    */
/* -------------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 38px; padding: 0 var(--sp-4);
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--surface); color: var(--text);
  font-size: var(--fs-sm); font-weight: 500; line-height: 1; white-space: nowrap;
  cursor: pointer; text-decoration: none; user-select: none;
  transition: background-color .12s, border-color .12s, color .12s, box-shadow .12s;
}
.btn:hover { background: var(--surface-2); color: var(--text); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-ink); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--err); }
.btn-sm { min-height: 30px; padding: 0 var(--sp-3); font-size: var(--fs-xs); }
.btn-lg { min-height: 44px; padding: 0 var(--sp-5); font-size: var(--fs-base); }
.btn-block { width: 100%; }
.btn .spinner { display: none; }
.btn.is-loading .spinner { display: inline-block; }
.btn.is-loading { pointer-events: none; }
.btn svg { width: 16px; height: 16px; flex: none; }

.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: rui-spin .7s linear infinite; display: inline-block; flex: none;
}
@keyframes rui-spin { to { transform: rotate(360deg); } }

/* -------------------------------------------------------------------------- */
/* Forms                                                                      */
/* -------------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: var(--fs-sm); font-weight: 500; color: var(--text); display: flex; justify-content: space-between; gap: var(--sp-2); }
.field-label .opt { font-weight: 400; color: var(--text-faint); font-size: var(--fs-xs); }
.input, .select, .textarea {
  width: 100%; min-height: 38px; padding: 8px 12px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  font-size: var(--fs-base); transition: border-color .12s, box-shadow .12s;
}
.textarea { min-height: 120px; resize: vertical; line-height: var(--lh-base); }
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--err); }
.input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--err) 25%, transparent); }
.select {
  appearance: none; -webkit-appearance: none; padding-right: 34px; cursor: pointer;
  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='M3 4.5l3 3 3-3' fill='none' stroke='%23888' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
.input-affix { position: relative; display: flex; align-items: stretch; }
.input-affix .input { flex: 1; }
.input-affix .affix {
  display: flex; align-items: center; padding: 0 10px; font-size: var(--fs-xs); color: var(--text-muted);
  background: var(--surface-2); border: 1px solid var(--border-strong); white-space: nowrap;
}
.input-affix .affix:first-child { border-right: 0; border-radius: var(--radius-md) 0 0 var(--radius-md); }
.input-affix .affix:last-child { border-left: 0; border-radius: 0 var(--radius-md) var(--radius-md) 0; }
.input-affix .affix:first-child + .input { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.input-affix .input:has(+ .affix) { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.hint { font-size: var(--fs-xs); color: var(--text-muted); }
.field-error { font-size: var(--fs-xs); color: var(--err); min-height: 0; }
.field-error:empty { display: none; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; }

.segmented {
  display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-md);
}
.segmented button, .segmented label {
  border: 0; background: transparent; padding: 6px 12px; border-radius: var(--radius-sm);
  font-size: var(--fs-sm); color: var(--text-muted); cursor: pointer; white-space: nowrap;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented button[aria-pressed="true"], .segmented label:has(input:checked) {
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm);
}
.segmented label:has(input:focus-visible) { box-shadow: var(--focus); }

.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  padding: 5px 10px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text-muted); font-size: var(--fs-xs);
  cursor: pointer; text-align: left;
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip-list { display: flex; flex-wrap: wrap; gap: var(--sp-2); }

/* -------------------------------------------------------------------------- */
/* Tabs (WAI-ARIA pattern, wired by RUI.initTabs)                             */
/* -------------------------------------------------------------------------- */
.tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; border: 0; background: transparent; cursor: pointer;
  padding: 10px 14px; font-size: var(--fs-sm); font-weight: 500; color: var(--text-muted); white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); }
.tab[aria-selected="true"]::after {
  content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px;
  background: var(--accent); border-radius: 2px;
}
.tab .count { margin-left: 6px; font-family: var(--font-mono); font-size: var(--fs-2xs); color: var(--text-faint); }
.tab-panel:focus-visible { box-shadow: none; }

/* -------------------------------------------------------------------------- */
/* Status, badges, callouts                                                   */
/* -------------------------------------------------------------------------- */
.status { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-xs); color: var(--text-muted); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); flex: none; }
.status[data-state="ok"] .status-dot { background: var(--ok); }
.status[data-state="warn"] .status-dot { background: var(--warn); }
.status[data-state="err"] .status-dot { background: var(--err); }
.status[data-state="busy"] .status-dot { background: var(--info); animation: rui-pulse 1.2s ease-in-out infinite; }
@keyframes rui-pulse { 50% { opacity: .35; } }

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px;
  border-radius: 999px; font-size: var(--fs-2xs); font-weight: 500; line-height: 1.6;
  background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); white-space: nowrap;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge-err { background: var(--err-soft); color: var(--err); border-color: transparent; }
.badge-info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge-accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.callout {
  display: flex; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border); border-left-width: 3px; border-radius: var(--radius-md);
  background: var(--surface-2); font-size: var(--fs-sm); color: var(--text);
}
.callout > div { min-width: 0; }
.callout-title { font-weight: 600; margin-bottom: 2px; }
.callout p + p { margin-top: 6px; }
.callout code { word-break: break-word; }
.callout-info { border-left-color: var(--info); background: var(--info-soft); }
.callout-warn { border-left-color: var(--warn); background: var(--warn-soft); }
.callout-err { border-left-color: var(--err); background: var(--err-soft); }
.callout-ok { border-left-color: var(--ok); background: var(--ok-soft); }

.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  gap: var(--sp-2); padding: var(--sp-8) var(--sp-5); color: var(--text-muted); font-size: var(--fs-sm);
}
.empty-state svg { width: 28px; height: 28px; color: var(--text-faint); }
.empty-state strong { color: var(--text); font-weight: 600; font-size: var(--fs-base); }

.provenance {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: var(--fs-2xs); color: var(--text-faint); letter-spacing: 0.01em;
}
.provenance::before { content: ""; width: 6px; height: 6px; border-radius: 1px; background: currentColor; opacity: .6; }

/* -------------------------------------------------------------------------- */
/* Data display                                                               */
/* -------------------------------------------------------------------------- */
.stat { padding: var(--sp-4); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); min-width: 0; }
.stat-label { font-size: var(--fs-xs); color: var(--text-muted); }
.stat-value { font-size: var(--fs-xl); font-weight: 600; letter-spacing: -0.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: var(--fs-xs); color: var(--text-faint); margin-top: 2px; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px var(--sp-5); font-size: var(--fs-sm); margin: 0; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; color: var(--text); font-variant-numeric: tabular-nums; min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 480px) { .kv { grid-template-columns: 1fr; gap: 2px; } .kv dd { margin-bottom: 8px; } }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th, .table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: var(--fs-xs); font-weight: 500; color: var(--text-muted); background: var(--surface-2); white-space: nowrap; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.table .row-highlight td { background: var(--accent-soft); }

/* Horizontal probability bars (RUI.renderBars) */
.bars { display: flex; flex-direction: column; gap: 10px; margin: 0; padding: 0; list-style: none; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 160px) 1fr 56px; align-items: center; gap: var(--sp-3); font-size: var(--fs-sm); }
.bar-label { display: flex; align-items: center; gap: 8px; color: var(--text-muted); min-width: 0; }
.bar-label span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row.is-top .bar-label { color: var(--text); font-weight: 600; }
.bar-swatch { width: 10px; height: 10px; border-radius: 2px; flex: none; }
.bar-track { height: 8px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; border-radius: 999px; background: var(--accent); transition: width .5s cubic-bezier(.2,.7,.2,1); }
.bar-value { text-align: right; font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.bar-row.is-top .bar-value { color: var(--text); }
@media (max-width: 480px) { .bar-row { grid-template-columns: minmax(80px, 110px) 1fr 50px; gap: var(--sp-2); } }

/* Confusion matrix (RUI.renderMatrix) */
.matrix-wrap { overflow-x: auto; }
.matrix { border-collapse: separate; border-spacing: 2px; font-size: var(--fs-xs); margin: 0 auto; }
.matrix th { font-weight: 500; color: var(--text-muted); padding: 4px 6px; white-space: nowrap; }
.matrix thead th { vertical-align: bottom; }
.matrix thead th span { display: inline-block; writing-mode: vertical-rl; transform: rotate(180deg); max-height: 120px; }
.matrix tbody th { text-align: right; }
.matrix td {
  min-width: 44px; height: 38px; text-align: center; border-radius: 3px;
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
}
.matrix td.diag { outline: 1.5px solid color-mix(in srgb, var(--text) 35%, transparent); outline-offset: -1.5px; }
.matrix-axis { font-size: var(--fs-2xs); color: var(--text-faint); font-family: var(--font-mono); text-transform: uppercase; letter-spacing: .06em; }

/* XY plot (RUI.plotXY) */
.plot { width: 100%; height: auto; display: block; font-family: var(--font-mono); }
.plot .axis line, .plot .axis path { stroke: var(--border-strong); }
.plot .grid line { stroke: var(--border); stroke-dasharray: 2 3; }
.plot text { fill: var(--text-muted); font-size: 10px; }
.plot .axis-title { fill: var(--text-muted); font-size: 11px; font-family: var(--font-sans); }
.legend { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4); font-size: var(--fs-xs); color: var(--text-muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 14px; height: 3px; border-radius: 2px; }
.legend-swatch.dot { width: 10px; height: 10px; border-radius: 50%; }

/* Pipeline stepper */
.stepper { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.step { position: relative; display: grid; grid-template-columns: 28px 1fr; gap: var(--sp-3); padding-bottom: var(--sp-5); }
.step:last-child { padding-bottom: 0; }
.step::before {
  content: ""; position: absolute; left: 13px; top: 28px; bottom: 0; width: 2px; background: var(--border);
}
.step:last-child::before { display: none; }
.step[data-state="done"]::before { background: var(--ok); opacity: .5; }
.step-icon {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--border-strong);
  background: var(--surface); display: grid; place-items: center;
  font-family: var(--font-mono); font-size: var(--fs-2xs); font-weight: 600; color: var(--text-muted);
  position: relative; z-index: 1;
}
.step[data-state="running"] .step-icon { border-color: var(--info); color: var(--info); }
.step[data-state="running"] .step-icon::after {
  content: ""; position: absolute; inset: -5px; border-radius: 50%;
  border: 2px solid var(--info); border-right-color: transparent; animation: rui-spin 1s linear infinite;
}
.step[data-state="done"] .step-icon { border-color: var(--ok); background: var(--ok); color: #fff; }
.step[data-state="error"] .step-icon { border-color: var(--err); background: var(--err); color: #fff; }
.step[data-state="skipped"] .step-icon { border-style: dashed; }
.step-body { min-width: 0; padding-top: 3px; }
.step-title { font-size: var(--fs-sm); font-weight: 600; display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.step-desc { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 2px; }
.step-meta { font-family: var(--font-mono); font-size: var(--fs-2xs); color: var(--text-faint); margin-left: auto; }

/* Progress bar (indeterminate) */
.progress { height: 3px; background: var(--surface-3); border-radius: 999px; overflow: hidden; position: relative; }
.progress::after {
  content: ""; position: absolute; inset: 0; width: 35%; background: var(--accent); border-radius: 999px;
  animation: rui-indet 1.3s ease-in-out infinite;
}
@keyframes rui-indet { from { transform: translateX(-100%); } to { transform: translateX(300%); } }

/* Skeleton */
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: rui-shimmer 1.4s infinite; border-radius: var(--radius-sm); }
@keyframes rui-shimmer { to { background-position: -200% 0; } }

/* Tooltip: <span data-tip="..."> */
[data-tip] { position: relative; }
[data-tip]:hover::after, [data-tip]:focus-visible::after {
  content: attr(data-tip); position: absolute; left: 50%; bottom: calc(100% + 6px); transform: translateX(-50%);
  width: max-content; max-width: 260px; padding: 6px 9px; border-radius: var(--radius-sm);
  background: #1c1f24; color: #f4f4f2; font-size: var(--fs-xs); line-height: 1.4; font-weight: 400;
  white-space: normal; text-align: left; z-index: 60; pointer-events: none; box-shadow: var(--shadow-md);
}
.info-dot {
  display: inline-grid; place-items: center; width: 15px; height: 15px; border-radius: 50%;
  border: 1px solid var(--border-strong); font-size: 10px; color: var(--text-muted); cursor: help; font-weight: 600;
}

/* Disclosure */
details.disclosure { border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
details.disclosure > summary {
  list-style: none; cursor: pointer; padding: 10px 14px; font-size: var(--fs-sm); font-weight: 500;
  display: flex; align-items: center; gap: var(--sp-2);
}
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary::before {
  content: ""; width: 6px; height: 6px; border-right: 1.5px solid var(--text-muted); border-bottom: 1.5px solid var(--text-muted);
  transform: rotate(-45deg); transition: transform .15s; flex: none;
}
details.disclosure[open] > summary::before { transform: rotate(45deg); }
details.disclosure > .disclosure-body { padding: 0 14px 14px; }
pre.code {
  margin: 0; padding: var(--sp-3) var(--sp-4); background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-md); overflow: auto; font-size: var(--fs-xs); line-height: 1.6; max-height: 360px;
  white-space: pre-wrap; word-break: break-word;
}

/* Long-form text (markdown output) */
.prose { font-size: var(--fs-base); line-height: 1.7; color: var(--text); overflow-wrap: anywhere; }
.prose > * + * { margin-top: 0.85em; }
.prose h1, .prose h2, .prose h3, .prose h4 { margin-top: 1.6em; letter-spacing: -0.01em; }
.prose h1 { font-size: 1.5em; } .prose h2 { font-size: 1.28em; } .prose h3 { font-size: 1.1em; } .prose h4 { font-size: 1em; }
.prose > :first-child { margin-top: 0; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li + li { margin-top: 0.3em; }
.prose code { background: var(--surface-2); padding: 1px 5px; border-radius: 3px; }
.prose pre { background: var(--surface-2); padding: var(--sp-3); border-radius: var(--radius-md); overflow: auto; }
.prose pre code { background: none; padding: 0; }
.prose blockquote { margin: 0; padding-left: var(--sp-4); border-left: 3px solid var(--border-strong); color: var(--text-muted); }
.prose hr { border: 0; border-top: 1px solid var(--border); }
.prose a { word-break: break-all; }

/* Toasts */
.toast-region { position: fixed; right: var(--sp-4); bottom: var(--sp-4); z-index: 80; display: flex; flex-direction: column; gap: var(--sp-2); max-width: min(380px, calc(100vw - 32px)); }
.toast {
  padding: 10px 14px; border-radius: var(--radius-md); background: #1c1f24; color: #f4f4f2;
  font-size: var(--fs-sm); box-shadow: var(--shadow-md); border-left: 3px solid var(--info);
  animation: rui-toast-in .18s ease-out;
}
.toast[data-kind="err"] { border-left-color: #f97066; }
.toast[data-kind="ok"] { border-left-color: #47cd89; }
@keyframes rui-toast-in { from { transform: translateY(6px); opacity: 0; } }

/* Footer */
.app-footer { border-top: 1px solid var(--border); margin-top: var(--sp-9); padding: var(--sp-6) 0 var(--sp-8); font-size: var(--fs-xs); color: var(--text-muted); }
.app-footer .container { display: flex; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; }
.app-footer p { max-width: 80ch; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
