/* Thread Gauge RUL — design system v2 (production-grade, dark-mode-aware) */

/* ─────────────────────────── Design tokens — strict monochrome (B&W only) */
:root {
  /* Surface ladder — pure white background, layered greys */
  --bg: #ffffff;
  --bg-tint: #f7f7f7;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --surface-3: #f2f2f2;
  /* Ink ladder — pure black down through neutral greys */
  --ink: #000000;
  --ink-2: #1a1a1a;
  --muted: #595959;
  --subtle: #8a8a8a;
  --line: #e5e5e5;
  --line-strong: #bfbfbf;
  /* "Accent" is still black — no hue, no chroma. Semantic vars retained
     so the codebase doesn't have to be rewritten, but they all resolve
     to greyscale and rely on weight / fill / dashes for differentiation. */
  --accent: #000000;
  --accent-2: #000000;
  --accent-soft: #f2f2f2;
  --accent-ring: rgba(0, 0, 0, 0.22);
  --success: #000000;
  --success-soft: #f2f2f2;
  --warning: #000000;
  --warning-soft: #f7f7f7;
  --danger: #000000;
  --danger-soft: #efefef;
  /* Spacing — 4px scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 48px;
  /* Type scale */
  --text-xs: 11px;
  --text-sm: 12px;
  --text-base: 14px;
  --text-md: 15px;
  --text-lg: 17px;
  --text-xl: 22px;
  --text-2xl: 28px;
  --text-3xl: 40px;
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;
  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 999px;
  --radius: var(--radius-md);   /* back-compat alias */
  /* Elevation — restrained, layered */
  --shadow-1: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 1px rgba(15, 23, 42, 0.03);
  --shadow-2: 0 4px 12px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-3: 0 12px 32px rgba(15, 23, 42, 0.10), 0 2px 6px rgba(15, 23, 42, 0.05);
  /* Motion */
  --dur-fast: 120ms;
  --dur-base: 200ms;
  --dur-slow: 360ms;
  --ease-out: cubic-bezier(0.2, 0, 0, 1);
  --ease-spring: cubic-bezier(0.32, 0.72, 0, 1);
  --transition: var(--dur-base) var(--ease-out);   /* back-compat alias */
  /* Monochrome "gradient" — pure black field, used only on the active model tab */
  --gradient-accent: #000000;
  --gradient-surface: transparent;
}
/* No dark theme — light mode only, per spec. */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-feature-settings: "cv11", "ss01", "ss03";
  font-size: var(--text-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color var(--dur-slow) var(--ease-out), color var(--dur-slow) var(--ease-out);
}
body { min-height: 100vh; }

.shell { position: relative; z-index: 1; }

button, input, select { font: inherit; color: inherit; }
::selection { background: #000; color: #fff; }

/* Focus ring — accessible and brand-coherent */
:where(button, input, select, textarea, a, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Scrollbar polish (Chromium / WebKit) */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: var(--radius-full); border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: var(--text-xl); font-weight: var(--weight-semibold); letter-spacing: -0.018em; }
h2 { font-size: var(--text-md); font-weight: var(--weight-semibold); letter-spacing: -0.01em; }
h3 { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Entrance animation utility (applied via JS or markup) */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.6; transform: scale(1.08); }
}
@keyframes shimmer {
  0%   { background-position: -480px 0; }
  100% { background-position: 480px 0; }
}
.fade-in { animation: fadeUp var(--dur-slow) var(--ease-out) both; }

/* Skeleton loader (used while LLM responds) */
.skeleton {
  background: linear-gradient(90deg, var(--surface-3) 0%, var(--surface-2) 50%, var(--surface-3) 100%);
  background-size: 480px 100%;
  border-radius: var(--radius-sm);
  animation: shimmer 1.6s linear infinite;
  color: transparent;
  user-select: none;
}

.shell {
  max-width: 1440px;
  margin: 0 auto;
  padding: var(--space-7) var(--space-6) var(--space-8);
}

/* ─────────────────────────── top bar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-5);
  border-bottom: 1px solid var(--line);
}
.topbar p { color: var(--muted); margin-top: var(--space-1); font-size: var(--text-sm); }
.top-actions { display: flex; gap: var(--space-2); align-items: center; }

.pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  padding: 6px 12px;
  border-radius: var(--radius-full);
  background: #fff;
  color: #000;
  border: 1px solid var(--line-strong);
  letter-spacing: 0.02em;
  transition: transform var(--dur-fast) var(--ease-out);
}
.pill.ready   { background: #000; color: #fff; border-color: #000; }
.pill.warning { background: #fff; color: #000; border-color: #000; border-style: dashed; }
.pill.model   { background: #fff; color: var(--muted); border-color: var(--line); }
/* Live pulse dot on the "Ready" pill — white-on-black */
.pill.ready::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
  animation: pulse 1.6s var(--ease-out) infinite;
}

/* Theme toggle removed — light mode only, per spec.
   The button is hidden rather than ripped out so we don't have to touch HTML/JS. */
.theme-toggle { display: none !important; }

/* ─────────────────────────── metric strip — KPI cards */
.metric-strip {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-6);
  overflow: hidden;
  box-shadow: var(--shadow-1);
}
.metric-strip > div {
  background: var(--surface);
  padding: var(--space-4) var(--space-5);
  transition: background var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
  position: relative;
}
.metric-strip > div:hover {
  background: var(--surface-2);
}
.metric-strip > div::after {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: var(--gradient-accent);
  opacity: 0;
  transition: opacity var(--dur-base) var(--ease-out);
}
.metric-strip > div:hover::after { opacity: 1; }
.metric-strip span {
  display: block;
  font-size: var(--text-xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: var(--weight-medium);
}
.metric-strip strong {
  display: block;
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.018em;
  margin: var(--space-1) 0 var(--space-1);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.metric-strip small { display: block; font-size: var(--text-xs); color: var(--subtle); }

/* ─────────────────────────── layout */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 4fr);
  gap: 24px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-1);
  transition: border-color var(--dur-base) var(--ease-out), box-shadow var(--dur-base) var(--ease-out);
}
.panel:hover { box-shadow: var(--shadow-2); }

.panel-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.subtle { color: var(--muted); font-size: 12px; }

/* ─────────────────────────── form */
label {
  display: grid;
  gap: 6px;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
label.inline { flex-direction: row; align-items: center; gap: 8px; }

input, select {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  font-size: 13px;
  font-weight: 400;
  color: var(--ink);
  text-transform: none;
  letter-spacing: normal;
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
input::placeholder { color: var(--subtle); }

.grid { display: grid; gap: 12px; }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid.compact { gap: 8px; }

.test-picker {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
  padding: 12px 14px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent-soft);
}
.test-picker-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
}
.test-picker-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.test-picker-hint { font-size: 11px; color: var(--muted); }
.test-picker-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.test-outcome {
  font-size: 12px;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
}
.test-outcome.hidden { display: none; }
.test-outcome strong { font-variant-numeric: tabular-nums; }
.primary-btn.small { height: 32px; padding: 0 14px; font-size: 12px; }

.cycle-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.cycle-toolbar .subtle { font-size: 11px; color: var(--muted); }
.cycle-controls {
  display: grid;
  gap: 0;
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.cycle-controls-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.cycle-count-label { min-width: 160px; }
.cycle-accordion-list {
  display: grid;
  gap: 8px;
}
.cycle-accordion {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.cycle-accordion[open] {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-1);
}
.cycle-accordion > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface-2);
  user-select: none;
}
.cycle-accordion > summary::-webkit-details-marker { display: none; }
.cycle-accordion > summary::before {
  content: "›";
  font-size: 16px;
  color: var(--muted);
  transition: transform var(--transition);
}
.cycle-accordion[open] > summary::before { transform: rotate(90deg); }
.cycle-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}
.cycle-summary-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
}
.cycle-summary-meta {
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cycle-current-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #fff;
  background: #000;
  border-radius: 999px;
  padding: 4px 8px;
}
.cycle-body {
  display: grid;
  gap: 12px;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--line);
}
.cycle-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.legacy-form-fields { display: none; }

.gauge-picker {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 18px;
}

.side-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 18px;
}

.side-box {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  background: var(--surface-2);
  transition: border-color var(--transition);
}
.side-box[data-state="fail"] { border-color: var(--danger); background: var(--danger-soft); }
.side-box[data-state="pass"] { border-color: var(--success); }
.side-box .side-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.side-box h3 { color: var(--ink); text-transform: none; font-size: 13px; letter-spacing: 0; }
.side-state {
  font-size: 10px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  background: #f3f4f6;
  color: var(--muted);
  letter-spacing: 0.04em;
}
.side-box[data-state="fail"] .side-state { background: var(--danger); color: #fff; }
.side-box[data-state="pass"] .side-state { background: var(--success); color: #fff; }

/* collapsible measurement detail */
details.measurement-details {
  margin-top: 10px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
details.measurement-details > summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
  list-style: none;
  padding: 4px 0;
  user-select: none;
}
details.measurement-details > summary::-webkit-details-marker { display: none; }
details.measurement-details > summary::before {
  content: "›";
  display: inline-block;
  margin-right: 6px;
  transition: transform var(--transition);
}
details.measurement-details[open] > summary::before { transform: rotate(90deg); }
details.measurement-details .grid { margin-top: 8px; }

.action-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

button {
  height: 38px;
  padding: 0 18px;
  border: 0;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.01em;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
}
.primary-btn {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.25);
}
.primary-btn:hover:not(:disabled) { background: #1a1a1a; }
.primary-btn:active:not(:disabled) { transform: translateY(1px); }
.primary-btn:disabled { background: var(--line-strong); cursor: not-allowed; box-shadow: none; }

.ghost-btn {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line-strong);
}
.ghost-btn:hover { background: var(--surface-2); }

#form-status { color: var(--muted); font-size: 12px; margin-left: auto; }

/* ─────────────────────────── prediction output */
.status-chip {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: #f3f4f6;
  color: var(--muted);
  letter-spacing: 0.04em;
  transition: background var(--transition), color var(--transition);
}
.status-chip.pass { background: var(--success-soft); color: var(--success); }
.status-chip.failed { background: var(--danger-soft); color: var(--danger); }

.prediction-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-3);
}
/* Hero tile — the RUL is the most important number on the page. Spans 2 cols,
   gets a subtle gradient accent and a larger figure. */
.prediction-grid > div:first-child {
  grid-column: span 2;
  background: linear-gradient(135deg, var(--accent-soft) 0%, var(--surface-2) 100%);
  border: 1px solid var(--accent-soft);
  position: relative;
  overflow: hidden;
}
.prediction-grid > div:first-child::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--gradient-accent);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.prediction-grid > div:first-child strong { font-size: var(--text-3xl); }

.prediction-grid > div {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  transition: transform var(--dur-base) var(--ease-out), border-color var(--dur-base) var(--ease-out), background var(--dur-base) var(--ease-out);
}
.prediction-grid > div.pulse {
  animation: pulse-in var(--dur-slow) var(--ease-spring);
}
@keyframes pulse-in {
  0% { transform: scale(0.96); opacity: 0.5; }
  60% { transform: scale(1.015); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
.prediction-grid span {
  display: block;
  font-size: var(--text-xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: var(--weight-medium);
}
.prediction-grid strong {
  display: block;
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  margin: var(--space-1) 0 var(--space-1);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.018em;
  color: var(--ink);
}
.prediction-grid small { display: block; font-size: var(--text-xs); color: var(--subtle); }

.rule-box {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--warning-soft);
  border: 1px solid var(--line-strong);
  font-size: 12px;
  color: #000;
  line-height: 1.55;
}
.rule-box.pass { background: var(--success-soft); border-color: var(--line-strong); color: var(--success); }
.rule-box.fail { background: var(--danger-soft); border-color: var(--line-strong); color: #000; }

/* ─────────────────────────── diagnostics */
.diagnostics-box {
  margin-top: 16px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  transition: opacity var(--transition);
}
.diagnostics-box.hidden { display: none; }
.diagnostics-box h3 { color: var(--ink); text-transform: none; letter-spacing: 0; font-size: 13px; margin-bottom: 10px; }
.diag-interpretation { color: var(--muted); margin-bottom: 12px; font-size: 12px; line-height: 1.55; }

.diag-breaches { display: flex; flex-wrap: wrap; gap: 10px; }
.diag-breach {
  flex: 1 1 220px;
  background: var(--danger-soft);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 10px 12px;
}
.diag-breach h4 {
  font-size: 11px;
  font-weight: 600;
  color: var(--danger);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}
.diag-breach ul { margin: 0; padding-left: 16px; font-size: 12px; }
.diag-breach li { margin: 2px 0; color: var(--ink); }
.diag-breach strong { font-variant-numeric: tabular-nums; }
.diag-good {
  background: var(--success-soft);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--success);
}
.diag-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.diag-metrics div {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
}
.diag-metrics span {
  display: block;
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.diag-metrics strong {
  display: block;
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
}

/* ─────────────────────────── drivers */
.driver-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 18px;
}
.driver-grid h3 { color: var(--ink); text-transform: none; letter-spacing: 0; font-size: 13px; margin-bottom: 10px; }

.driver-list { display: flex; flex-direction: column; gap: 8px; }
.driver-list.empty {
  color: var(--muted);
  background: var(--surface-2);
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: 12px;
  font-size: 12px;
  text-align: center;
}
.driver-row {
  display: grid;
  gap: 4px;
  padding: 6px 0;
}
.driver-row > div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 12px;
}
.driver-row strong { font-weight: 500; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.driver-row small { color: var(--subtle); font-variant-numeric: tabular-nums; }
.driver-row span {
  display: block;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), #000);
  transition: width 360ms cubic-bezier(0.2, 0, 0, 1);
}

/* ─────────────────────────── history */
.history-panel { margin-top: 24px; }
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--surface-2);
}
tr:hover td { background: var(--surface-2); }
.failed-row td { background: var(--danger-soft); }
.failed-row:hover td { background: var(--surface-3); }

/* ─────────────────────────── visuals */
.visual-gallery {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.visual-link {
  display: grid;
  gap: 6px;
  color: var(--ink);
  font-size: 11px;
  font-weight: 500;
  transition: transform var(--transition);
}
.visual-link:hover { transform: translateY(-2px); text-decoration: none; }
.visual-link img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
}

/* ─────────────────────────── responsive */
.model-warning {
  margin-bottom: 14px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--warning-soft);
  border: 1px solid var(--line-strong);
  color: #000;
  font-size: 12px;
  line-height: 1.55;
}
.model-warning.hidden { display: none; }
.model-warning::before {
  content: "⚠";
  font-weight: 700;
  margin-right: 8px;
  color: var(--warning);
}

.charts-panel { margin-top: 24px; }
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px;
}
.chart-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  background: var(--surface-2);
}
.chart-card h3 {
  color: var(--ink);
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
  margin-bottom: 4px;
}
.chart-help { font-size: 11px; color: var(--muted); margin-bottom: 10px; }
.chart-card canvas { width: 100% !important; max-height: 220px; }

@media (max-width: 760px) {
  .charts-grid { grid-template-columns: 1fr; }
}

.model-nav {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin: 0 0 var(--space-6) 0;
  padding: var(--space-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-full);
  background: var(--surface);
  box-shadow: var(--shadow-1);
}
.model-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 16px;
  background: transparent;
  border: 0;
  text-align: center;
  cursor: pointer;
  color: var(--muted);
  border-radius: var(--radius-full);
  transition: color var(--dur-base) var(--ease-out), background var(--dur-base) var(--ease-out);
  position: relative;
  z-index: 1;
  min-height: 60px;
}
.model-tab:hover { color: var(--ink-2); }
.model-tab.active {
  background: #000;
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}
.model-tab .tab-title {
  font-weight: var(--weight-semibold);
  font-size: 13px;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.model-tab .tab-sub {
  font-size: 10px;
  color: inherit;
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
  max-width: 100%;
}
.model-tab.active .tab-sub { opacity: 0.85; }

@media (max-width: 1180px) {
  .workspace { grid-template-columns: 1fr; }
  .metric-strip { grid-template-columns: repeat(3, 1fr); }
  .visual-gallery { grid-template-columns: repeat(2, 1fr); }
  .cycle-controls-head {
    display: grid;
    grid-template-columns: 1fr;
    align-items: start;
  }
}
@media (max-width: 760px) {
  .shell { padding: 20px 16px 48px; }
  .topbar { flex-direction: column; align-items: flex-start; }
  .metric-strip, .prediction-grid, .grid.two, .side-grid, .driver-grid { grid-template-columns: 1fr; }
  .cycle-meta-grid { grid-template-columns: 1fr; }
  .cycle-summary { flex-wrap: wrap; }
  .test-picker-row, .chat-form { grid-template-columns: 1fr; }
}

/* ─────────────────────────── explainability panel */
.explain-panel { margin-top: 24px; }

.narration-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}
.narration-list.empty {
  color: var(--muted);
  font-size: 12px;
  background: var(--surface-2);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}
.narration-item {
  padding: 10px 14px;
  border-radius: 6px;
  border-left: 3px solid var(--line-strong);
  font-size: 13px;
  line-height: 1.55;
  background: var(--surface-2);
  transition: background var(--transition);
}
.narration-item.info  { border-left-color: var(--accent); background: var(--accent-soft); color: #000; }
.narration-item.warn  { border-left-color: var(--warning); background: var(--warning-soft); color: #000; }
.narration-item.alert { border-left-color: var(--danger); background: var(--danger-soft); color: #000; }

.counterfactual-box {
  margin: 16px 0;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.counterfactual-box.hidden { display: none; }
.counterfactual-box h3 {
  color: var(--ink);
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
  margin-bottom: 6px;
}
.counterfactual-text { font-size: 12px; color: var(--muted); line-height: 1.55; margin-bottom: 12px; }
.counterfactual-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
}
.counterfactual-grid div {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
}
.counterfactual-grid span {
  display: block;
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.counterfactual-grid strong {
  display: block;
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
}
.counterfactual-grid small { font-size: 11px; color: var(--subtle); }

.model-explanation-box {
  margin-top: 18px;
  padding: 16px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
}
.me-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.me-head h3 {
  color: var(--ink);
  text-transform: none;
  letter-spacing: 0;
  font-size: 14px;
}
.me-explanation {
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink);
  white-space: pre-wrap;
  margin: 0 0 12px 0;
}
.me-explanation.loading { color: var(--muted); font-style: italic; }
.me-explanation.error { color: var(--danger); }
.me-footnote {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.55;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.drift-chip {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: #f3f4f6;
  color: var(--muted);
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.drift-chip.hidden { display: none; }
.drift-chip.stable     { background: var(--success-soft); color: var(--success); }
.drift-chip.degrading  { background: var(--warning-soft); color: var(--warning); }
.drift-chip.rapid      { background: var(--danger-soft); color: var(--danger); animation: pulse 1.4s var(--ease-out) infinite; }
.drift-chip.improving  { background: var(--accent-soft); color: var(--accent); }

/* ─────────────────────────── Dual feature-importance panel */
.importance-box {
  margin: var(--space-4) 0;
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.importance-box h3 {
  color: var(--ink);
  text-transform: none;
  letter-spacing: 0;
  font-size: var(--text-base);
  margin-bottom: var(--space-2);
}
.importance-grid {
  display: grid;
  grid-template-columns: 1fr;   /* single-column now that Overall is gone */
  gap: var(--space-5);
  margin-top: var(--space-3);
}
.importance-box.hidden { display: none; }
.importance-col h4 {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: var(--space-3);
}
.lime-loading {
  font-size: var(--text-sm);
  color: var(--muted);
  font-style: italic;
  padding: var(--space-3) 0;
}
.local-imp .lime-bar-cell, .global-imp .lime-bar-cell { background: #fff; }
.global-imp .lime-bar {
  /* Overall importance is unsigned — just left-aligned filled black bars. */
  background: #000;
  justify-self: start;
  grid-column: 1 / -1;   /* spans both halves of the bar-cell */
}
.global-imp .lime-bar-cell::before { display: none; }   /* no centre line */
@media (max-width: 1100px) {
  .importance-grid { grid-template-columns: 1fr; }
}

.lime-box {
  margin: 16px 0;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.lime-box.hidden { display: none; }
.lime-box h3 {
  color: var(--ink);
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
  margin-bottom: 6px;
}
.lime-hint { font-size: 11px; color: var(--muted); line-height: 1.55; margin-bottom: 12px; }
.lime-rows {
  display: grid;
  grid-template-columns: 220px 1fr 80px;
  gap: 4px 14px;
  align-items: center;
  font-size: 12px;
}
.lime-rows .lime-name {
  font-family: Consolas, monospace;
  font-size: 11px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lime-rows .lime-bar-cell {
  display: grid;
  grid-template-columns: 1fr 1px 1fr;
  height: 14px;
  align-items: center;
  background: linear-gradient(to right, #fafafa 0%, #fafafa 50%, #fafafa 50%, #fafafa 100%);
  border: 1px solid var(--line);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
}
.lime-rows .lime-bar-cell::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--line-strong);
}
.lime-rows .lime-bar {
  height: 100%;
  border-radius: 2px;
  align-self: stretch;
}
/* Mono LIME bars — directional cue via hatching pattern instead of colour.
   "up" (pushes RUL up) = solid black; "down" (pushes RUL down) = diagonal stripes. */
.lime-rows .lime-bar.up   { background: #000; justify-self: start; grid-column: 3; }
.lime-rows .lime-bar.down {
  background-image: repeating-linear-gradient(
    -45deg, #000 0 2px, transparent 2px 5px
  );
  background-color: transparent;
  border: 1px solid #000;
  justify-self: end;
  grid-column: 1;
}
.lime-rows .lime-weight {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  color: var(--muted);
}

.chat-box {
  margin-top: 18px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.chat-box h3 {
  color: var(--ink);
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
  margin-bottom: 4px;
}
.chat-hint { font-size: 11px; color: var(--muted); margin-bottom: 10px; line-height: 1.55; }
.chat-log {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 340px;
  overflow-y: auto;
  padding: 4px 2px;
  margin-bottom: 10px;
}
.chat-log:empty::before {
  content: "No questions asked yet.";
  font-size: 12px;
  color: var(--subtle);
  display: block;
  text-align: center;
  padding: 12px;
}
.chat-bubble {
  font-size: 13px;
  line-height: 1.55;
  padding: 9px 12px;
  border-radius: 10px;
  max-width: 88%;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.chat-bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 3px;
}
.chat-bubble.bot {
  align-self: flex-start;
  background: #f3f4f6;
  color: var(--ink);
  border-bottom-left-radius: 3px;
}
.chat-bubble.error {
  align-self: flex-start;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--line-strong);
  border-bottom-left-radius: 3px;
}
.chat-bubble.thinking { opacity: 0.7; font-style: italic; }
.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}
.chat-form input {
  height: 36px;
  font-size: 13px;
}

/* ─────────────────────────── Supabase auth — Stitch Calispec layout
 * Full-bleed overlay: top wordmark bar, centered card, system-id, footer.
 * 4 violet L-shaped corner brackets. Locks the shell while not signed in.
 * No flicker because auth.js adds .auth-locked synchronously.              */

.auth-overlay {
  position: fixed;
  inset: 0;
  display: none;                       /* shown only when body.auth-locked */
  flex-direction: column;
  background: #f7f7f8;
  color: #111;
  z-index: 9000;
  overflow: hidden;
  animation: fadeUp var(--dur-base) var(--ease-out) both;
}
body.auth-locked .auth-overlay { display: flex; }
body.auth-locked .shell        { display: none; }

/* Four violet L-brackets at the page corners */
.auth-corner {
  position: absolute;
  width: 28px;
  height: 28px;
  border-color: #5b1d8c;             /* purple, matches reference */
  border-style: solid;
  border-width: 0;
  z-index: 2;
  pointer-events: none;
}
.auth-corner.tl { top: 14px;    left: 14px;    border-top-width:    2px; border-left-width:  2px; }
.auth-corner.tr { top: 14px;    right: 14px;   border-top-width:    2px; border-right-width: 2px; }
.auth-corner.bl { bottom: 14px; left: 14px;    border-bottom-width: 2px; border-left-width:  2px; }
.auth-corner.br { bottom: 14px; right: 14px;   border-bottom-width: 2px; border-right-width: 2px; }

/* Top wordmark bar */
.auth-topbar {
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 32px;
  border-bottom: 1px solid #e5e7eb;
  background: #ffffff;
  flex: 0 0 auto;
}
.auth-wordmark {
  font-family: "Inter", system-ui, sans-serif;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.04em;
  color: #111;
}

/* Center column */
.auth-main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  gap: 18px;
}

/* Card */
.auth-card {
  width: min(360px, 100%);
  padding: 28px 28px 24px;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Brand row */
.auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 0 0;
}
.auth-logo {
  display: block;
  max-width: 132px;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}
.auth-logo-fallback {
  font-family: "Inter", system-ui, sans-serif;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: #1e6dc6;
  font-size: 22px;
}

.auth-title {
  margin: -4px 0 0;
  text-align: center;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: #111;
  text-transform: none;          /* override the global h1 rule */
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 4px;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.auth-field > span,
.auth-field-head > span {
  font-size: 10px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: #8a8a8a;
  font-weight: 600;
}
.auth-field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.auth-field > input {
  height: 36px;
  padding: 0 12px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  background: #ffffff;
  font-size: 13px;
  color: #111;
  font-family: inherit;
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}
.auth-field > input::placeholder { color: #b3b3b3; }
.auth-field > input:focus {
  outline: none;
  border-color: #111;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.08);
}

.auth-primary {
  width: 100%;
  height: 40px;
  margin-top: 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  background: #111;
  color: #fff;
  border: 1px solid #111;
  border-radius: 4px;
}
.auth-primary:hover:not(:disabled) { background: #000; }

.auth-status {
  font-size: 12px;
  margin: 0;
  color: var(--muted);
  min-height: 16px;
  line-height: 1.4;
  text-align: center;
}
.auth-status[data-kind="error"] { color: #b00020; font-weight: 600; }
.auth-status[data-kind="warn"]  { color: #6b4f00; }

.auth-meta {
  margin: 0;
  text-align: center;
  font-size: 12px;
  color: #6b7280;
}
.auth-link-btn {
  background: none;
  border: 0;
  padding: 0;
  margin-left: 4px;
  color: #2563eb;
  font-weight: 500;
  cursor: pointer;
  font-size: inherit;
  font-family: inherit;
}
.auth-link-btn:hover { text-decoration: underline; }
.auth-forgot {
  margin-left: 0;
  font-size: 10px;
  letter-spacing: 0.04em;
  font-weight: 500;
  text-transform: none;
  color: #2563eb;
}

/* System ID + operational line below the card */
.auth-systemid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
}
.auth-systemid p {
  margin: 0;
  font-family: "JetBrains Mono", ui-monospace, "Cascadia Mono", Menlo, monospace;
  font-size: 10px;
  letter-spacing: 0.10em;
  color: #8a8a8a;
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.auth-status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #16a34a;             /* green operational dot */
}

/* Bottom footer bar */
.auth-footer-bar {
  flex: 0 0 auto;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  border-top: 1px solid #e5e7eb;
  background: transparent;
  font-size: 10px;
  letter-spacing: 0.10em;
  color: #6b7280;
  text-transform: uppercase;
}
.auth-footer-links { display: inline-flex; gap: 24px; }
.auth-footer-link {
  color: #6b7280;
  text-decoration: none;
  font-weight: 500;
}
.auth-footer-link:hover { color: #111; }

/* Top-bar user pill — visible only when signed in (auth.js toggles .hidden) */
.auth-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 4px 10px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: 11px;
}
.auth-pill .auth-user-email {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.auth-signout-btn {
  height: 22px;
  padding: 0 8px;
  border-radius: var(--radius-full);
  border: 1px solid #000;
  background: #000;
  color: #fff;
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: var(--weight-semibold);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.auth-signout-btn:hover { background: #fff; color: #000; }

/* ─────────────────────────── Loaded-gauge label below the random button
 * Shown after Load-random-gauge resolves. Renders the gauge serial,
 * description, cycle count, and ground-truth chip (failed/never-failed).
 */
.cycle-toolbar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.loaded-gauge-label {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-left: 3px solid #000;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 12px;
  animation: fadeUp var(--dur-base) var(--ease-out) both;
}
.loaded-gauge-name {
  color: #000;
  font-size: 13px;
  letter-spacing: 0.01em;
}
.loaded-gauge-name strong { font-weight: 700; }
.loaded-gauge-meta { color: var(--muted); }
.loaded-gauge-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-weight: 600;
}
.loaded-gauge-chip.fail { background: #000; color: #fff; }
.loaded-gauge-chip.ok   { background: #fff; color: #000; border: 1px solid #bfbfbf; }

/* ─────────────────────────── Paragraph-style model explanation
 * The LLM now returns 4 short paragraphs with **bold** key terms,
 * which formatExplanation() converts to <p> + <strong>. Spacing
 * + line-height tuned for scannability.
 */
.me-explanation { line-height: 1.6; }
.me-explanation p {
  margin: 0 0 10px;
  font-size: 13.5px;
  color: #1a1a1a;
}
.me-explanation p:last-child { margin-bottom: 0; }
.me-explanation strong {
  font-weight: 700;
  color: #000;
  background: linear-gradient(180deg, transparent 65%, #f0f0f0 65%);
  padding: 0 2px;
}

/* ─────────────────────────── Bullet list inside the model explanation
 * The LLM now returns its answer as a Markdown bullet list with one
 * topic per bullet. formatExplanation() converts that to <ul><li>;
 * these styles make it scannable: tight spacing, bold labels at the
 * left, the soft highlighter on every <strong> inside.
 */
.me-explanation ul {
  margin: 0;
  padding: 0;
  list-style: none;
}
.me-explanation li {
  margin: 0 0 10px;
  padding: 8px 12px 8px 14px;
  border-left: 2px solid #000;
  background: var(--surface-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 13.5px;
  line-height: 1.55;
  color: #1a1a1a;
}
.me-explanation li:last-child { margin-bottom: 0; }
.me-explanation li strong {
  font-weight: 700;
  color: #000;
  background: linear-gradient(180deg, transparent 65%, #eaeaea 65%);
  padding: 0 2px;
}
/* When the LLM's first <strong> is the bullet's topic label (e.g.
   "Headline:"), give it a tiny bit more breathing room. */
.me-explanation li strong:first-child { margin-right: 4px; }

/* ─────────────────────────── LIME progress bar
 * Shown while /api/lime is computing (~5-30s on the live deploy).
 * The fill is animated by JS so it eases to 90% over ~25s and snaps
 * to 100% the instant the response lands. The animated stripes inside
 * make it look "alive" even while the JS hasn't ticked the width.
 */
.lime-progress-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px 2px;
  animation: fadeUp var(--dur-base) var(--ease-out) both;
}
.lime-progress-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
}
.lime-progress-title {
  color: var(--ink);
  font-weight: 600;
}
.lime-progress-eta {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
}
.lime-progress-track {
  height: 8px;
  width: 100%;
  border-radius: var(--radius-full);
  background: var(--surface-3);
  overflow: hidden;
  position: relative;
}
.lime-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(
    90deg,
    var(--accent) 0%,
    #2563eb 50%,
    var(--accent) 100%
  );
  background-size: 200% 100%;
  border-radius: var(--radius-full);
  /* The width is set by JS each 200ms; CSS transition smooths it. */
  transition: width 320ms cubic-bezier(0.2, 0, 0, 1);
  /* Continuous shimmer along the bar so it feels alive even when the
     width hasn't changed in 200ms. */
  animation: lime-progress-shine 1.6s linear infinite;
}
@keyframes lime-progress-shine {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.lime-progress-note {
  margin: 0;
  font-size: 11px;
  line-height: 1.45;
  color: var(--muted);
}
