/* =============================================================================
   SAGE — Redesigned stylesheet
   Editorial dashboard, sage-forward palette, light + dark, fully responsive.
   Drop-in replacement for static/css/style.css. No HTML class hooks were
   removed; all dashboard.html selectors used by the AJAX swap still exist.
   ============================================================================= */

/* ── Design tokens ──────────────────────────────────────────────────────── */
:root {
  /* Brand */
  --sage-50:  #f3f6f1;
  --sage-100: #e6ece1;
  --sage-200: #cbd6c2;
  --sage-300: #a8b89c;
  --sage-400: #859877;
  --sage-500: #6d7a63;   /* original brand */
  --sage-600: #55604d;
  --sage-700: #424b3c;
  --sage-800: #2f352b;
  --sage-900: #1d211b;

  /* Surfaces (light) */
  --bg:           #fafbf9;
  --bg-elevated:  #ffffff;
  --bg-sunken:    #f3f5f1;
  --bg-sidebar:   #ffffff;
  --bg-overlay:   rgba(15, 18, 14, 0.55);

  /* Text */
  --fg:           #1d211b;
  --fg-muted:     #5c665c;
  --fg-subtle:    #8a958a;
  --fg-on-brand:  #ffffff;

  /* Lines */
  --border:        #e4e8e1;
  --border-strong: #cfd6c9;
  --ring:          rgba(109, 122, 99, 0.35);

  /* Semantic */
  --success:    #4f8a4f;
  --success-bg: #eaf3ea;
  --warning:    #b8860b;
  --warning-bg: #fbf3df;
  --danger:     #a54a4a;
  --danger-bg:  #f7e7e7;
  --info:       #4a6fa5;
  --info-bg:    #e7eef7;

  /* Elevation */
  --shadow-xs: 0 1px 2px rgba(20, 28, 18, 0.04);
  --shadow-sm: 0 1px 3px rgba(20, 28, 18, 0.06), 0 1px 2px rgba(20, 28, 18, 0.04);
  --shadow-md: 0 6px 16px -6px rgba(20, 28, 18, 0.10), 0 2px 4px rgba(20, 28, 18, 0.04);
  --shadow-lg: 0 18px 40px -16px rgba(20, 28, 18, 0.18), 0 4px 10px rgba(20, 28, 18, 0.06);

  /* Radius */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;
  --r-pill: 999px;

  /* Layout */
  --sidebar-w: 248px;
  --sidebar-w-collapsed: 72px;
  --topbar-h: 60px;
  --content-max: 1200px;

  /* Type */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font-brand: "Fraunces", "Iowan Old Style", "Apple Garamond", Georgia, "Times New Roman", serif;

  /* Motion */
  --ease: cubic-bezier(.2, .7, .2, 1);
  --dur-fast: 120ms;
  --dur:      200ms;
  --dur-slow: 360ms;
}

[data-theme="dark"] {
  --bg:          #14181a;
  --bg-elevated: #1c2124;
  --bg-sunken:   #10141a;   /* fixed: was unset, caused unreadable text in dark mode */
  --bg-sidebar:  #161a1d;
  --bg-overlay:  rgba(0, 0, 0, 0.65);

  --fg:        #ecefe8;
  --fg-muted:  #a8b0a6;
  --fg-subtle: #6e7670;

  --border:        #262d2a;
  --border-strong: #34403a;
  --ring:          rgba(168, 184, 156, 0.45);

  --sage-500: #a8b89c;       /* lift brand for contrast on dark */
  --sage-600: #c2cdb8;

  --success-bg: rgba(79,138,79,0.16);
  --warning-bg: rgba(184,134,11,0.18);
  --danger-bg:  rgba(165,74,74,0.18);
  --info-bg:    rgba(74,111,165,0.18);

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 8px 24px -8px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 24px 50px -20px rgba(0, 0, 0, 0.7);
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
img, svg { display: block; max-width: 100%; }
button { font: inherit; color: inherit; cursor: pointer; background: none; border: none; }
a { color: inherit; text-decoration: none; }
input, select, textarea { font: inherit; color: inherit; }
ul, ol { list-style: none; }

:focus-visible {
  outline: 2px solid var(--sage-500);
  outline-offset: 2px;
  border-radius: 4px;
}

::selection { background: var(--sage-200); color: var(--sage-900); }
[data-theme="dark"] ::selection { background: var(--sage-700); color: var(--fg); }

/* ── Layout shell ───────────────────────────────────────────────────────── */
.app-shell { min-height: 100vh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: color-mix(in oklab, var(--bg) 88%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.topbar-tagline-link {
  display: flex;
  align-items: center;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}
.topbar-tagline-link:hover .brand-tagline { color: var(--fg); }

.brand-icon-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  flex-shrink: 0;
}
.brand-icon {
  width: 28px; height: 28px;
  border-radius: 8px;
  display: block;
  object-fit: contain;
  box-shadow: var(--shadow-sm);
}
.brand-icon-wrap .dot {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--sage-400), var(--sage-600));
  box-shadow: var(--shadow-sm);
}
.brand-wordmark {
  font-family: var(--font-brand);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--fg);
  flex-shrink: 0;
  line-height: 1;
}
.brand-tagline {
  font-family: var(--font-brand);
  font-size: 14px;
  font-weight: 400;
  font-style: italic;
  color: var(--fg-muted);
  letter-spacing: 0.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  transition: color var(--dur) var(--ease);
}
@media (max-width: 640px) {
  .brand-tagline { font-size: 13px; }
}
.topbar-right { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-md);
  color: var(--fg-muted);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.icon-btn:hover { background: var(--bg-sunken); color: var(--fg); }
.icon-btn svg { width: 20px; height: 20px; }

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: calc(100vh - var(--topbar-h));
}
.layout.sidebar-collapsed { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }

/* ── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
  position: sticky;
  top: var(--topbar-h);
  align-self: start;
  height: calc(100vh - var(--topbar-h));
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width var(--dur) var(--ease);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  min-height: 52px;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand-mini {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
  padding: 2px 4px;
  border-radius: var(--r-sm);
  transition: opacity var(--dur) var(--ease);
}
.sidebar-brand-mini:hover { opacity: 0.85; }
.sidebar-brand-mini .brand-wordmark {
  font-size: 20px;
  letter-spacing: 0.01em;
}
.sidebar-toggle-btn { display: inline-flex; }
.sidebar-close-btn { display: none; }
/* When collapsed: hide wordmark, stack icon + toggle vertically and center them */
.layout.sidebar-collapsed .sidebar-header {
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  padding: 10px 6px;
  min-height: auto;
}
.layout.sidebar-collapsed .sidebar-brand-mini { display: none; }
@media (max-width: 900px) {
  .sidebar-toggle-btn { display: none; }
  .sidebar-close-btn { display: inline-flex; }
}

.sidebar-menu { flex: 1; padding: 14px 10px; overflow-y: auto; }
.sidebar-menu .group-label {
  padding: 6px 12px 8px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-subtle);
}
.layout.sidebar-collapsed .group-label { display: none; }

.sidebar-menu li { margin-bottom: 2px; }
.sidebar-menu a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  color: var(--fg-muted);
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.sidebar-menu a:hover { background: var(--bg-sunken); color: var(--fg); }
.sidebar-menu a.active {
  background: color-mix(in oklab, var(--sage-500) 14%, transparent);
  color: var(--sage-600);
}
.sidebar-menu a.active::before {
  content: "";
  position: absolute;
  left: -10px;
  top: 8px; bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--sage-500);
}
.sidebar-menu .menu-icon { display: inline-flex; width: 20px; height: 20px; flex-shrink: 0; }
.sidebar-menu .menu-icon svg { width: 100%; height: 100%; }
.sidebar-menu .menu-text { flex: 1; font-size: 14px; }
.layout.sidebar-collapsed .menu-text { display: none; }
.layout.sidebar-collapsed .sidebar-menu a { justify-content: center; padding: 10px; }
.layout.sidebar-collapsed .sidebar-menu a.active::before { display: none; }

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--fg-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.layout.sidebar-collapsed .sidebar-footer .footer-text { display: none; }
.layout.sidebar-collapsed .sidebar-footer { justify-content: center; }

/* Theme switch */
.theme-toggle {
  width: 36px; height: 36px;
  border-radius: var(--r-md);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--fg-muted);
  transition: background var(--dur) var(--ease);
}
.theme-toggle:hover { background: var(--bg-sunken); color: var(--fg); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ── Mobile drawer ──────────────────────────────────────────────────────── */
.scrim {
  position: fixed; inset: 0;
  background: var(--bg-overlay);
  opacity: 0; pointer-events: none;
  transition: opacity var(--dur) var(--ease);
  z-index: 45;
}
.scrim.open { opacity: 1; pointer-events: auto; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    width: 280px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform var(--dur-slow) var(--ease);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .topbar .menu-trigger { display: inline-flex; }
}
@media (min-width: 901px) {
  .topbar .menu-trigger { display: none; }
}

/* ── Main content ───────────────────────────────────────────────────────── */
.main-content {
  padding: 28px clamp(20px, 4vw, 40px) 80px;
  min-width: 0;
}

/* Page header used by Model Info / Guide / About — aligned with dataset hero */
.page-header {
  max-width: var(--content-max);
  margin: 8px auto 28px;
}
.page-header .eyebrow {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--sage-600);
  background: var(--sage-50);
  padding: 4px 10px;
  border-radius: var(--r-pill);
  margin-bottom: 16px;
}
.page-header h1 {
  margin-top: 0;
  font-family: var(--font-brand);
  font-weight: 600;
  font-size: clamp(2rem, 4vw, 2.75rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--fg);
}
.page-header .lede {
  margin-top: 16px;
  max-width: 100ch;
  color: var(--fg-muted);
  font-size: 1.05rem;
  line-height: 1.65;
}
[data-theme="dark"] .page-header .eyebrow {
  background: color-mix(in oklab, var(--sage-500) 14%, transparent);
}

.page-container {
  max-width: var(--content-max);
  margin: 0 auto;
  display: grid;
  gap: 20px;
}

/* Cards */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 22px 24px;
  box-shadow: var(--shadow-xs);
}
.card h2 {
  font-family: var(--font-brand);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 14px;
  display: flex; align-items: center; gap: 10px;
  color: var(--fg);
}
.card h3 {
  margin-top: 18px;
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.card p { color: var(--fg-muted); margin-top: 8px; }
.card p strong { color: var(--fg); }
.card ul, .card ol { padding-left: 20px; margin-top: 8px; color: var(--fg-muted); }
.card ul li, .card ol li { margin: 4px 0; }
.card ul li strong { color: var(--fg); }
.card a { color: var(--sage-600); border-bottom: 1px solid color-mix(in oklab, var(--sage-500) 40%, transparent); }
.card a:hover { color: var(--sage-700); }
.card code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--bg-sunken);
  padding: 1px 6px;
  border-radius: 4px;
}

/* ── Dashboard grid ─────────────────────────────────────────────────────── */
.dashboard-container {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 24px;
  max-width: var(--content-max);
  margin: 0 auto;
  align-items: start;
}
@media (max-width: 1024px) {
  .dashboard-container { grid-template-columns: 1fr; }
}

.form-panel,
.results-panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 24px;
  box-shadow: var(--shadow-xs);
}

.results-panel { position: sticky; top: calc(var(--topbar-h) + 20px); }
@media (max-width: 1024px) { .results-panel { position: static; } }

.form-panel h2, .results-panel h2 {
  font-family: var(--font-brand);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--fg);
  display: flex; align-items: center; gap: 10px;
}
.form-subtitle { color: var(--fg-muted); margin: 8px 0 20px; font-size: 0.95rem; line-height: 1.6; }

/* Form sections (collapsible) */
.form-section {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  margin-top: 12px;
  overflow: hidden;
  background: var(--bg-elevated);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.form-section:hover { border-color: var(--border-strong); }
.form-section > h3 {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
  background: var(--bg-sunken);
  cursor: pointer;
  user-select: none;
  text-transform: none;
  letter-spacing: 0;
  margin: 0;
}
.form-section > h3 .chev {
  transition: transform var(--dur) var(--ease);
  color: var(--fg-subtle);
}
.form-section.collapsed > h3 .chev { transform: rotate(-90deg); }
.form-section .fields-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 18px;
  padding: 18px 16px;
  transition: max-height var(--dur-slow) var(--ease), padding var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.form-section.collapsed .fields-grid {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
  overflow: hidden;
}
@media (max-width: 600px) {
  .form-section .fields-grid { grid-template-columns: 1fr; }
}

.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field label {
  font-size: 13px;
  color: var(--fg-muted);
  font-weight: 500;
}

.form-field input[type="number"],
.form-field select {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  font-size: 14px;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease);
}
.form-field input[type="number"]:focus,
.form-field select:focus {
  outline: none;
  border-color: var(--sage-500);
  box-shadow: 0 0 0 3px var(--ring);
}
.form-field select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%235c665c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* Toggle switch */
.toggle-field { display: flex; align-items: center; height: 40px; }
.toggle-field input[type="checkbox"] {
  appearance: none;
  position: relative;
  width: 40px; height: 22px;
  background: var(--border-strong);
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: background var(--dur) var(--ease);
}
.toggle-field input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur) var(--ease);
}
.toggle-field input[type="checkbox"]:checked { background: var(--sage-500); }
.toggle-field input[type="checkbox"]:checked::after { transform: translateX(18px); }
.toggle-field input[type="checkbox"]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--ring);
}

/* Submit row */
.form-actions {
  position: sticky;
  bottom: 0;
  margin: 18px -24px -24px;
  padding: 14px 24px;
  background: color-mix(in oklab, var(--bg-elevated) 92%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
  display: flex; gap: 10px; justify-content: flex-end;
  z-index: 5;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 18px;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease), transform var(--dur-fast) var(--ease), box-shadow var(--dur) var(--ease);
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary, .btn-submit {
  background: var(--sage-600);
  color: var(--fg-on-brand);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover, .btn-submit:hover {
  background: var(--sage-700);
  box-shadow: var(--shadow-md);
}
[data-theme="dark"] .btn-primary, [data-theme="dark"] .btn-submit {
  background: var(--sage-500); color: #14181a;
}
[data-theme="dark"] .btn-primary:hover, [data-theme="dark"] .btn-submit:hover {
  background: var(--sage-600);
}
.btn-ghost, .btn-reset {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--fg);
}
.btn-ghost:hover, .btn-reset:hover { background: var(--bg-sunken); }

/* ── Download / CTA buttons (e.g. About → Download Thesis) ──────────────── */
/* Defensive: ensure anchor-styled buttons remain readable in light mode.
   Many download buttons were authored with dark-mode contrast only. */
a.btn,
.btn-download,
.btn-thesis,
.thesis-download,
.download-btn {
  background: var(--sage-600);
  color: var(--fg-on-brand);
  border-color: transparent;
  text-decoration: none;
  box-shadow: var(--shadow-sm);
}
a.btn:hover,
.btn-download:hover,
.btn-thesis:hover,
.thesis-download:hover,
.download-btn:hover {
  background: var(--sage-700);
  color: var(--fg-on-brand);
  box-shadow: var(--shadow-md);
}
[data-theme="dark"] a.btn,
[data-theme="dark"] .btn-download,
[data-theme="dark"] .btn-thesis,
[data-theme="dark"] .thesis-download,
[data-theme="dark"] .download-btn {
  background: var(--sage-500);
  color: #14181a;
}
[data-theme="dark"] a.btn:hover,
[data-theme="dark"] .btn-download:hover,
[data-theme="dark"] .btn-thesis:hover,
[data-theme="dark"] .thesis-download:hover,
[data-theme="dark"] .download-btn:hover {
  background: var(--sage-600);
  color: #14181a;
}

/* Outline variant — keeps text visible on light backgrounds */
a.btn-outline,
.btn-outline {
  background: transparent;
  color: var(--sage-700);
  border-color: var(--sage-600);
  text-decoration: none;
}
a.btn-outline:hover,
.btn-outline:hover {
  background: var(--sage-50, var(--bg-sunken));
  color: var(--sage-700);
}
[data-theme="dark"] a.btn-outline,
[data-theme="dark"] .btn-outline {
  color: var(--sage-300, var(--sage-500));
  border-color: var(--sage-500);
}
[data-theme="dark"] a.btn-outline:hover,
[data-theme="dark"] .btn-outline:hover {
  background: rgba(255,255,255,0.04);
  color: var(--sage-300, var(--sage-500));
}

.btn .spinner {
  width: 16px; height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: none;
}
.btn.is-loading { pointer-events: none; opacity: 0.85; }
.btn.is-loading .spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Results panel ──────────────────────────────────────────────────────── */
.results-panel { display: flex; flex-direction: column; gap: 16px; }

.result-card {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 18px 20px;
  background: var(--bg-elevated);
  animation: rise var(--dur-slow) var(--ease) both;
}
.result-card h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 12px;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Hero prediction card */
.prediction-card {
  background: linear-gradient(135deg,
    color-mix(in oklab, var(--sage-500) 10%, var(--bg-elevated)),
    var(--bg-elevated));
  border-color: color-mix(in oklab, var(--sage-500) 30%, var(--border));
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: center;
}
.prediction-card .predicted-tier { display: flex; flex-direction: column; gap: 2px; }
.prediction-card .tier-class {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--sage-600);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.prediction-card .tier-name {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.1;
}
.prediction-card .tier-range {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--fg-muted);
  margin-top: 4px;
}

/* Confidence ring */
.confidence-ring {
  --pct: 0;
  width: 84px; height: 84px;
  position: relative;
  display: grid; place-items: center;
}
.confidence-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.confidence-ring circle { fill: none; stroke-width: 8; }
.confidence-ring .track { stroke: var(--border); }
.confidence-ring .fill {
  stroke: var(--sage-500);
  stroke-linecap: round;
  stroke-dasharray: 226.2;   /* 2πr where r=36 */
  stroke-dashoffset: 226.2;
  transition: stroke-dashoffset 1s var(--ease);
}
.confidence-ring .label {
  position: absolute;
  inset: 0;
  display: grid; place-items: center;
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 700;
}

/* Legacy fallback (kept for AJAX swap of old markup) */
.confidence-meter { display: none; }

/* Probability bars */
.probability-bars { display: flex; flex-direction: column; gap: 8px; }
.prob-item { display: grid; grid-template-columns: minmax(96px, 130px) 1fr; gap: 12px; align-items: center; }
.prob-label {
  font-size: 12px;
  color: var(--fg-muted);
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.prob-bar-container {
  position: relative;
  height: 22px;
  background: var(--bg-sunken);
  border-radius: var(--r-pill);
  overflow: visible;
}
.prob-bar-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  min-width: 2px;
  max-width: 100%;
  background: linear-gradient(90deg, var(--sage-400), var(--sage-600));
  border-radius: var(--r-pill);
  width: 0;
  animation: grow 0.9s var(--ease) forwards;
}
/* The % label is anchored to the END of the fill via inline `left: <pct>%`.
   - Default (wide enough): sits INSIDE the fill, right-aligned, white text.
   - .is-outside (fill < 15%): sits OUTSIDE the fill, left-aligned, muted text. */
.prob-bar-value {
  position: absolute;
  top: 50%;
  transform: translate(-100%, -50%);
  padding-right: 8px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: #fff;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  animation: fadeInBar 0.4s var(--ease) 0.6s forwards;
}
.prob-bar-value.is-outside {
  transform: translate(0, -50%);
  padding-right: 0;
  padding-left: 6px;
  color: var(--fg-muted);
}
.prob-item.is-predicted .prob-bar-fill {
  background: linear-gradient(90deg, var(--sage-500), var(--sage-700));
  box-shadow: 0 0 0 2px color-mix(in oklab, var(--sage-500) 30%, transparent);
}
@keyframes grow { from { width: 0; } }
@keyframes fadeInBar { to { opacity: 1; } }
.probability-bars.small .prob-bar-container { height: 18px; }
.probability-bars.small .prob-bar-value { font-size: 10px; }

/* Base model accordion */
.model-details {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  margin-top: 8px;
  overflow: hidden;
}
.model-details summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  background: var(--bg-sunken);
  display: flex; align-items: center; justify-content: space-between;
  user-select: none;
}
.model-details summary::-webkit-details-marker { display: none; }
.model-details summary::after {
  content: "+";
  font-family: var(--font-mono);
  color: var(--fg-subtle);
  transition: transform var(--dur) var(--ease);
}
.model-details[open] summary::after { content: "−"; }
.model-details .probability-bars { padding: 12px 14px; }

/* Recommendations */
.recommendation-list { padding-left: 0 !important; list-style: none !important; }
.recommendation-list li {
  position: relative;
  padding: 10px 12px 10px 36px;
  margin: 8px 0 !important;
  background: var(--bg-sunken);
  border-radius: var(--r-md);
  border-left: 3px solid var(--border-strong);
  font-size: 13px;
  color: var(--fg);
}
.recommendation-list li::before {
  content: "";
  position: absolute;
  left: 12px; top: 13px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--border-strong) center/12px no-repeat;
}
.recommendation-list.positive li {
  border-left-color: var(--success);
  background: var(--success-bg);
}
.recommendation-list.positive li::before {
  background-color: var(--success);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><polyline points='20 6 9 17 4 12'/></svg>");
}
.recommendation-list.improvements li {
  border-left-color: var(--warning);
  background: var(--warning-bg);
}
.recommendation-list.improvements li::before {
  background-color: var(--warning);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><polyline points='12 5 12 19'/><polyline points='5 12 12 19 19 12'/></svg>");
}
.recommendation-list .impact {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  font-size: 11px;
  font-family: var(--font-mono);
  border-radius: var(--r-pill);
  background: rgba(0,0,0,0.06);
  color: var(--fg-muted);
}
[data-theme="dark"] .recommendation-list .impact { background: rgba(255,255,255,0.08); }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--fg-muted);
}
.empty-state h2 { font-family: var(--font-brand); font-weight: 600; font-size: 1.5rem; letter-spacing: -0.01em; color: var(--fg); margin-bottom: 8px; justify-content: center; }
.empty-state .empty-icon {
  margin: 18px auto 0;
  width: 72px; height: 72px;
  border-radius: 50%;
  background: var(--bg-sunken);
  display: grid; place-items: center;
  font-size: 32px;
}

/* ── Model Info / Guide / About specific ────────────────────────────────── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}
.metric-tile {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 16px;
}
.metric-tile .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--fg-subtle);
}
.metric-tile .value {
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 700;
  color: var(--fg);
}

.shap-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
  margin-top: 12px;
}
.shap-plot {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.shap-plot:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}
.shap-plot h4 {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--fg-muted);
}
.shap-plot img {
  width: 100%;
  height: auto;
  border-radius: var(--r-sm);
  cursor: zoom-in;
  background: #fff;
}
.shap-plot .image-placeholder {
  padding: 30px 12px;
  text-align: center;
  background: var(--bg-sunken);
  border-radius: var(--r-sm);
  font-size: 12px;
  color: var(--fg-muted);
}

/* Lightbox */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(10, 14, 10, 0.85);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
  animation: fade var(--dur) var(--ease);
}
.lightbox.open { display: flex; }
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  background: #fff;
}
.lightbox-close {
  position: absolute;
  top: 16px; right: 16px;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  color: #fff;
  display: grid; place-items: center;
}
.lightbox-close:hover { background: rgba(255,255,255,0.22); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* About — team list */
.team-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
  list-style: none !important;
  padding: 0 !important;
  margin-top: 8px;
}
.team-list li {
  background: var(--bg-sunken);
  padding: 10px 14px;
  border-radius: var(--r-md);
  font-size: 14px;
  border-left: 3px solid var(--sage-500);
}

.note {
  background: var(--info-bg);
  border-left: 3px solid var(--info);
  padding: 12px 14px;
  border-radius: var(--r-md);
  margin-top: 14px;
  font-size: 13px;
  color: var(--fg-muted) !important;
}
.note strong { color: var(--fg); }

/* Guide — TOC */
.guide-grid {
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: 28px;
  align-items: start;
  max-width: var(--content-max);
  margin: 0 auto;
}
@media (max-width: 900px) { .guide-grid { grid-template-columns: 1fr; } .toc { display: none; } }
.toc {
  position: sticky;
  top: calc(var(--topbar-h) + 20px);
  font-size: 13px;
}
.toc .toc-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-subtle);
  margin-bottom: 10px;
}
.toc a {
  display: block;
  padding: 6px 10px;
  color: var(--fg-muted);
  border-left: 2px solid transparent;
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.toc a:hover { color: var(--fg); }
.toc a.active {
  color: var(--sage-600);
  border-left-color: var(--sage-500);
  background: color-mix(in oklab, var(--sage-500) 8%, transparent);
}

/* ── Page transition ────────────────────────────────────────────────────── */
.main-content { animation: page-enter 320ms var(--ease); }
@keyframes page-enter {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
  html { scroll-behavior: auto; }
}

/* Print niceties */
@media print {
  .topbar, .sidebar, .form-actions { display: none !important; }
  .main-content { padding: 0; }
  .card, .result-card { box-shadow: none; border-color: #ccc; }
}

/* =============================================================================
   DATASET PAGE
   ============================================================================= */
.dataset-page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 8px 64px;
  display: flex;
  flex-direction: column;
  gap: 56px;
}

.dataset-hero { text-align: left; }
.dataset-hero .eyebrow {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--sage-600);
  background: var(--sage-50);
  padding: 4px 10px;
  border-radius: var(--r-pill);
  margin-bottom: 16px;
}
.dataset-hero h1 {
  font-family: var(--font-brand);
  font-weight: 600;
  font-size: clamp(2rem, 4vw, 2.75rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin: 0 0 16px;
  color: var(--fg);
}
.dataset-hero .lede {
  font-size: 1.05rem;
  line-height: 1.65;
  color: var(--fg-muted);
  max-width: 100ch;
  margin: 0;
}
.dataset-hero .lede code,
.dataset-section code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--sage-700);
}

/* Stats */
.dataset-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow-xs);
}
.stat-value {
  font-family: var(--font-brand);
  font-weight: 600;
  font-size: 2rem;
  line-height: 1;
  color: var(--sage-700);
}
.stat-label {
  font-size: 0.82rem;
  color: var(--fg-muted);
  letter-spacing: 0.01em;
}

/* Section */
.dataset-section h2 {
  font-family: var(--font-brand);
  font-weight: 600;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
  margin: 0 0 12px;
  color: var(--fg);
}
.section-intro {
  color: var(--fg-muted);
  line-height: 1.6;
  margin: 0 0 20px;
  max-width: 100ch;
}

/* Source cards */
.source-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}
.source-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--shadow-xs);
}
.source-card h3 {
  margin: 0 0 8px;
  font-size: 1.05rem;
  color: var(--sage-700);
}
.source-card p {
  color: var(--fg-muted);
  line-height: 1.55;
  margin: 0 0 14px;
  font-size: 0.93rem;
}

/* Chips */
.chips {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chips li {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--sage-700);
  background: var(--sage-50);
  border: 1px solid var(--sage-100);
  padding: 3px 9px;
  border-radius: var(--r-pill);
}
.chips.danger li {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: var(--danger-bg);
}

/* Pipeline */
.pipeline {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  counter-reset: step;
}
.pipeline li {
  display: flex;
  gap: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--sage-400);
  border-radius: var(--r-md);
  padding: 16px 18px;
}
.step-num {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--sage-100);
  color: var(--sage-700);
  display: grid;
  place-items: center;
  font-family: var(--font-brand);
  font-weight: 600;
  font-size: 0.95rem;
}
.pipeline h4 {
  margin: 4px 0 6px;
  font-size: 1rem;
  color: var(--fg);
}
.pipeline p {
  margin: 0;
  color: var(--fg-muted);
  font-size: 0.92rem;
  line-height: 1.55;
}

/* Schema table */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg-elevated);
}
.schema-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.schema-table th,
.schema-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.schema-table th {
  background: var(--bg-sunken);
  font-weight: 600;
  color: var(--fg);
  font-size: 0.82rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.schema-table tr:last-child td { border-bottom: none; }
.schema-table td:first-child { width: 80px; }

/* Feature groups */
.feature-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}
.feature-group {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 16px;
}
.feature-group h4 {
  margin: 0 0 10px;
  font-size: 0.9rem;
  color: var(--sage-700);
  letter-spacing: 0.01em;
}

.excluded-block {
  margin-top: 18px;
  background: var(--danger-bg);
  border: 1px solid var(--danger-bg);
  border-radius: var(--r-md);
  padding: 12px 16px;
}
.excluded-block summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--danger);
  font-size: 0.92rem;
}
.excluded-block .chips { margin-top: 12px; }

/* Scripts */
.script-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}
.script-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.script-card code {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  color: var(--sage-700);
  background: var(--sage-50);
  border: 1px solid var(--sage-100);
  padding: 2px 8px;
  border-radius: 4px;
  align-self: flex-start;
}
.script-card.output code {
  color: var(--success);
  background: var(--success-bg);
  border-color: var(--success-bg);
}
.script-card span {
  color: var(--fg-muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

/* Dark mode tweaks */
[data-theme="dark"] .dataset-hero .eyebrow,
[data-theme="dark"] .chips li,
[data-theme="dark"] .step-num,
[data-theme="dark"] .script-card code {
  background: rgba(133, 152, 119, 0.15);
  border-color: rgba(133, 152, 119, 0.25);
  color: var(--sage-300);
}
[data-theme="dark"] .schema-table th { background: var(--bg-sunken); }
