:root {
  --bg: #0b1020;
  --text: #e9ecf1;
  --muted: #b6bfd2;
  --accent: #7aa2ff;
  --bad: #ff7a7a;
  --ok: #7affc7;
  --border: rgba(255, 255, 255, 0.12);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --surface-1: rgba(255, 255, 255, 0.04);
  --surface-2: rgba(255, 255, 255, 0.02);
  --table-head-bg: rgba(15, 23, 50, 0.92);
  --table-head-text: #f8fafc;
  --table-head-border: rgba(255, 255, 255, 0.18);
  --table-row-hover: rgba(122, 162, 255, 0.06);
  --table-row-border: rgba(255, 255, 255, 0.08);
  --cfa-canvas-bg: rgba(0, 0, 0, 0.2);
  --tab-bg-active: #1f2937;
  --tab-bg-inactive: #374151;
  --tab-text-active: #e5e7eb;
  --tab-text-inactive: #9ca3af;
  --tab-border: #4b5563;
  --plot-bg: rgba(15, 23, 42, 0.45);
  --plot-border: rgba(255, 255, 255, 0.08);
  --plot-grid: rgba(255, 255, 255, 0.08);
  --plot-grid-strong: rgba(148, 163, 184, 0.6);
  --plot-tick: #94a3b8;
  --plot-axis-x: #ffb347;
  --plot-axis-y: #7aa2ff;
  --plot-point: #94a3b8;
  --plot-point-outline: rgba(15, 23, 42, 0.6);
  --plot-hull-a-fill: rgba(255, 179, 71, 0.18);
  --plot-hull-a-stroke: #ffb347;
  --plot-hull-b-fill: rgba(122, 162, 255, 0.18);
  --plot-hull-b-stroke: #7aa2ff;
  --plot-arrow-a: #ffb347;
  --plot-arrow-b: #7aa2ff;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica,
    Arial, "Apple Color Emoji", "Segoe UI Emoji";

  /* Resizable layout defaults */
  --topH: 520px; /* height of top region */
  --leftW: 56%; /* width of left top card */
  --minTopH: 300px;
  --maxTopH: 720px;
  --minLeftW: 34%;
  --maxLeftW: 72%;
}

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  background: radial-gradient(
      1200px 800px at 20% 10%,
      rgba(122, 162, 255, 0.2),
      transparent 60%
    ),
    radial-gradient(
      1000px 700px at 80% 0%,
      rgba(122, 255, 199, 0.12),
      transparent 60%
    ),
    var(--bg);
  min-height: 100vh;
}
body.light-mode {
  --bg: #f5f6fb;
  --text: #111827;
  --muted: #374151;
  --accent: #2563eb;
  --bad: #dc2626;
  --ok: #16a34a;
  --border: rgba(15, 23, 42, 0.14);
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
  --surface-1: rgba(255, 255, 255, 0.9);
  --surface-2: rgba(244, 246, 255, 0.75);
  --table-head-bg: #d3dbe8;
  --table-head-text: #111827;
  --table-head-border: rgba(15, 23, 42, 0.14);
  --table-row-hover: rgba(37, 99, 235, 0.08);
  --table-row-border: rgba(15, 23, 42, 0.08);
  --cfa-canvas-bg: rgba(15, 23, 42, 0.05);
  --tab-bg-active: #111827;
  --tab-bg-inactive: #e5e7eb;
  --tab-text-active: #f8fafc;
  --tab-text-inactive: #111827;
  --tab-border: rgba(15, 23, 42, 0.18);
  --plot-bg: rgba(15, 23, 42, 0.06);
  --plot-border: rgba(15, 23, 42, 0.18);
  --plot-grid: rgba(15, 23, 42, 0.08);
  --plot-grid-strong: rgba(15, 23, 42, 0.22);
  --plot-tick: #475569;
  --plot-axis-x: #b45309;
  --plot-axis-y: #1d4ed8;
  --plot-point: #64748b;
  --plot-point-outline: rgba(15, 23, 42, 0.5);
  --plot-hull-a-fill: rgba(245, 158, 11, 0.18);
  --plot-hull-a-stroke: #b45309;
  --plot-hull-b-fill: rgba(37, 99, 235, 0.18);
  --plot-hull-b-stroke: #1d4ed8;
  --plot-arrow-a: #b45309;
  --plot-arrow-b: #1d4ed8;
  background: radial-gradient(
      1200px 800px at 20% 10%,
      rgba(37, 99, 235, 0.12),
      transparent 60%
    ),
    radial-gradient(
      1000px 700px at 80% 0%,
      rgba(16, 185, 129, 0.12),
      transparent 60%
    ),
    var(--bg);
}
body.about-open {
  overflow: hidden;
}

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

/* Visual indicator for terms with tooltips */
.tooltip-term {
  border-bottom: 1px dotted rgba(122, 162, 255, 0.5);
  cursor: help;
  position: relative;
}

.tooltip-term:hover {
  border-bottom-color: rgba(122, 162, 255, 0.8);
}

/* JavaScript-based smart tooltips that escape overflow */
.smart-tooltip {
  position: fixed;
  left: -9999px !important;
  top: -9999px !important;
  padding: 10px 14px;
  background-color: rgba(15, 23, 42, 0.98);
  color: rgba(233, 236, 241, 1);
  border: 1px solid rgba(122, 162, 255, 0.3);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.5;
  white-space: normal;
  max-width: 320px;
  pointer-events: none;
  z-index: 10000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  text-align: left;
  opacity: 1;
  transition: opacity 0.18s ease;
}
body.light-mode .smart-tooltip {
  background-color: rgba(255, 255, 255, 0.98);
  color: #111827;
  border-color: rgba(37, 99, 235, 0.2);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.16);
}

.smart-tooltip.positioned {
  animation: tooltipFadeIn 0.5s ease;
  left: var(--tooltip-left) !important;
  top: var(--tooltip-top) !important;
}

.smart-tooltip.is-hiding {
  opacity: 0;
}

@keyframes tooltipFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Layout container: keep consistent left/right margins for ALL panels */
header,
.wrap,
.footer {
  /* full-width page, but content is centered and constrained */
  width: 100%;
  max-width: 1200px;
  min-width: 500px;
  margin: 0 auto;
}
.footer a {
  color: var(--accent);
  text-decoration: none;
}
header {
  padding: 28px 18px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.about-btn,
.theme-toggle {
  background: rgba(122, 162, 255, 0.14);
  color: #e9ecf1;
  border: 1px solid rgba(122, 162, 255, 0.35);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 12px;
  letter-spacing: 0.3px;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}
.about-btn:hover,
.theme-toggle:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
}
body.light-mode .about-btn,
body.light-mode .theme-toggle {
  background: rgba(37, 99, 235, 0.08);
  color: #111827;
  border-color: rgba(37, 99, 235, 0.35);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}
body.light-mode .about-btn:hover,
body.light-mode .theme-toggle:hover {
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
}

.about-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 24, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 2000;
}
.light-mode .about-backdrop {
  background: rgba(15, 23, 42, 0.18);
}
.about-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.about-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(460px, 90vw);
  height: 100vh;
  overflow-y: auto;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.98), rgba(8, 12, 24, 0.98));
  border-left: 1px solid rgba(122, 162, 255, 0.25);
  box-shadow: -12px 0 36px rgba(0, 0, 0, 0.45);
  padding: 24px 22px;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 2100;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.light-mode .about-panel {
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.98),
    rgba(244, 246, 255, 0.98)
  );
  border-left-color: rgba(37, 99, 235, 0.18);
  box-shadow: -12px 0 36px rgba(15, 23, 42, 0.12);
}
.about-panel.open {
  transform: translateX(0);
}
.about-panel h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0.3px;
}
.about-panel .close-btn {
  align-self: flex-end;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #e9ecf1;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}
.light-mode .about-panel .close-btn {
  border-color: rgba(15, 23, 42, 0.2);
  color: #111827;
}
.about-panel .about-text {
  color: #cfd6e8;
  font-size: 13px;
  line-height: 1.6;
}
.light-mode .about-panel .about-text,
.light-mode .about-panel ul {
  color: #374151;
}
.about-panel ul {
  padding-left: 18px;
  margin: 8px 0;
  color: #cfd6e8;
  font-size: 13px;
  line-height: 1.6;
}
.references-cite a {
  color: var(--accent);
  text-decoration: none;
}
.references-cite a:hover {
  text-decoration: underline;
}
.references-content {
  margin-top: 4px;
  padding-top: 12px;
  border-top: 1px solid rgba(122, 162, 255, 0.2);
  color: #cfd6e8;
  font-size: 13px;
  line-height: 1.6;
}
.light-mode .references-content {
  color: #374151;
  border-top-color: rgba(37, 99, 235, 0.18);
}
.references-content h1 {
  margin: 16px 0 6px;
  font-size: 14px;
  letter-spacing: 0.2px;
  color: #f8fafc;
}
.light-mode .references-content h1 {
  color: #111827;
}
.references-content p,
.references-content .MsoNormal {
  margin: 0 0 8px;
}
.references-content hr {
  border: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  margin: 12px 0;
}
.light-mode .references-content hr {
  border-top-color: rgba(15, 23, 42, 0.12);
}
.references-content a {
  color: var(--accent);
  text-decoration: none;
}
.references-content a:hover {
  text-decoration: underline;
}
.references-content .WordSection1 {
  margin: 0;
}
p.sub {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.4;
  max-width: 92ch;
}

.wrap {
  /* internal gutter + vertical spacing between panels */
  padding: 14px 18px 34px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

@media (max-width: 980px) {
  header,
  .wrap,
  .footer {
    max-width: 100%;
  }
}

/* TOP: 2 cards + vertical handle */

/* Remove previous resizable top region; frames are stacked vertically */
.topRegion {
  display: none;
}

/* Vertical resize handle */
/* hide legacy resize handles (no longer used) */
.vHandle {
  cursor: col-resize;
  position: relative;
  display: none;
}
.vHandle:after {
  display: none;
}

/* Horizontal resize handle */
.hHandle {
  display: none;
}
.hHandle:after {
  display: none;
}

.card {
  background: linear-gradient(
    180deg,
    var(--surface-1),
    var(--surface-2)
  );
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Frame-specific styles: collapsed vs expanded */
.frame .hd {
  cursor: pointer;
}
.frame .bd {
  display: block;
  max-height: 600px;
  overflow-y: auto;
}
.frame.collapsed .bd {
  display: none;
}
.frame.collapsed {
  opacity: 0.98;
}
.frame.disabled {
  opacity: 0.6;
  filter: grayscale(10%);
}
.frame.disabled .hd {
  cursor: not-allowed;
}
.frame.disabled .bd {
  display: none;
}
/* Use flex gap for spacing; avoid stacking margins fighting with gap */
.frame + .frame {
  margin-top: 0;
}
.card .hd {
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
body.light-mode .card .hd {
  background: rgba(15, 23, 42, 0.03);
}
.card .hd .title {
  font-weight: 650;
  font-size: 14px;
  letter-spacing: 0.3px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.pill {
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.12);
}
.light-mode .pill {
  background: rgba(15, 23, 42, 0.04);
}
.runtime-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.2px;
  border: 1px solid var(--runtime-color, rgba(122, 162, 255, 0.45));
  color: var(--runtime-color, #7aa2ff);
  background: var(--runtime-bg, rgba(122, 162, 255, 0.15));
}
.runtime-pill.tooltip-term {
  border-bottom: none;
}
.runtime-pill .runtime-label {
  color: var(--muted);
  font-weight: 600;
}
.runtime-pill .runtime-value {
  color: var(--runtime-color, #7aa2ff);
}
body.light-mode .runtime-pill {
  background: var(--runtime-bg-light, rgba(122, 162, 255, 0.12));
}
body.light-mode .runtime-pill .runtime-label {
  color: #4b5563;
}
.runtime-pill[data-runtime="very-short"] {
  --runtime-color: #1e3a8a;
  --runtime-bg: rgba(30, 58, 138, 0.22);
  --runtime-bg-light: rgba(30, 58, 138, 0.12);
}
.runtime-pill[data-runtime="short"] {
  --runtime-color: #1d4ed8;
  --runtime-bg: rgba(29, 78, 216, 0.2);
  --runtime-bg-light: rgba(29, 78, 216, 0.12);
}
.runtime-pill[data-runtime="moderate"] {
  --runtime-color: #3b82f6;
  --runtime-bg: rgba(59, 130, 246, 0.18);
  --runtime-bg-light: rgba(59, 130, 246, 0.12);
}
.runtime-pill[data-runtime="moderately-long"] {
  --runtime-color: #f59e0b;
  --runtime-bg: rgba(245, 158, 11, 0.2);
  --runtime-bg-light: rgba(245, 158, 11, 0.12);
}
.runtime-pill[data-runtime="long"] {
  --runtime-color: #f97316;
  --runtime-bg: rgba(249, 115, 22, 0.2);
  --runtime-bg-light: rgba(249, 115, 22, 0.12);
}
.runtime-pill[data-runtime="very-long"] {
  --runtime-color: #ea580c;
  --runtime-bg: rgba(234, 88, 12, 0.2);
  --runtime-bg-light: rgba(234, 88, 12, 0.12);
}
.runtime-pill[data-runtime="go-walk"] {
  --runtime-color: #c2410c;
  --runtime-bg: rgba(194, 65, 12, 0.22);
  --runtime-bg-light: rgba(194, 65, 12, 0.12);
}
.card .bd {
  padding: 16px;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
body.light-mode select,
body.light-mode input[type="number"],
body.light-mode input[type="text"],
body.light-mode input[type="search"] {
  background: #ffffff !important;
  color: #111827 !important;
  border-color: var(--table-row-border) !important;
}
body.light-mode select option {
  background: #ffffff;
  color: #111827;
}
input[type="file"] {
  display: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(122, 162, 255, 0.12);
  color: var(--text);
  cursor: pointer;
  user-select: none;
  transition: transform 0.06s ease, background 0.2s ease, border-color 0.2s ease;
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
}
.btn:hover {
  background: rgba(122, 162, 255, 0.18);
  border-color: rgba(122, 162, 255, 0.35);
}
.btn:active {
  transform: translateY(1px);
}
.btn.secondary {
  background: rgba(255, 255, 255, 0.06);
}
.btn.danger {
  background: rgba(255, 122, 122, 0.12);
}

.struct-type-filter {
  font-size: 10px;
  padding: 3px 6px;
  background: var(--tab-bg-inactive);
  color: var(--tab-text-inactive);
  border-color: var(--tab-border);
}

.struct-type-filter.is-active {
  background: var(--tab-bg-active);
  color: var(--tab-text-active);
  border-color: var(--tab-border);
}

#efaGenerateBtn,
#cfaRunBtn {
  background: rgba(122, 162, 255, 0.26);
  border-color: rgba(122, 162, 255, 0.65);
  font-weight: 700;
  letter-spacing: 0.2px;
}
#efaGenerateBtn:hover,
#cfaRunBtn:hover {
  background: rgba(122, 162, 255, 0.34);
  border-color: rgba(122, 162, 255, 0.8);
}

@keyframes cfa-run-flash {
  0% {
    box-shadow: 0 0 0 0 rgba(122, 162, 255, 0);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(122, 162, 255, 0.45);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(122, 162, 255, 0);
  }
}

#cfaRunBtn.cfa-run-flash {
  animation: cfa-run-flash 0.35s ease-in-out 2;
}

.kv {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}
.kv .box {
  background: rgba(0, 0, 0, 0.14);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
}
.kv .k {
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
  margin-bottom: 6px;
}

.cfa-resize-handle {
  width: 8px;
  cursor: col-resize;
  border-radius: 6px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.05),
    rgba(255, 255, 255, 0.02)
  );
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.cfa-var-grid {
  display: grid;
  grid-template-columns: repeat(
    auto-fill,
    minmax(min(100%, var(--cfa-var-tile-width, 120px)), var(--cfa-var-tile-width, 120px))
  );
  gap: 6px;
  justify-content: start;
  user-select: none;
}

.cfa-var-tile {
  padding: 6px 4px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: #cfd6e8;
  font-size: 11px;
  text-align: center;
  cursor: grab;
  white-space: nowrap;
  overflow: hidden;
}
body.light-mode .cfa-var-tile {
  border-color: rgba(15, 23, 42, 0.12);
  background: rgba(15, 23, 42, 0.04);
  color: #1f2937;
}

.cfa-var-tile.selected {
  background: rgba(122, 180, 255, 0.65);
  color: #fff;
}
body.light-mode .cfa-var-tile.selected {
  background: rgba(37, 99, 235, 0.18);
  color: #1d4ed8;
}

.cfa-var-tile.used {
  background: rgba(122, 180, 255, 0.25);
  color: #7ab4ff;
  pointer-events: none;
  opacity: 0.5;
  cursor: not-allowed;
}
body.light-mode .cfa-var-tile.used {
  background: rgba(37, 99, 235, 0.08);
  color: #6b7280;
}

.cfa-progress {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cfa-progress-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  color: var(--muted);
}

.cfa-progress-pct {
  font-variant-numeric: tabular-nums;
  color: #cfd6e8;
}

.cfa-progress-bar {
  height: 7px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.cfa-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #7ab4ff, #9cd2ff);
  transition: width 0.2s ease;
}

.cfa-progress-step.is-complete .cfa-progress-fill {
  background: linear-gradient(90deg, #7ab4ff, #7cffc7);
}

.cfa-progress-step.is-active .cfa-progress-label {
  color: #e2e8f7;
}
body.light-mode .cfa-progress-step.is-active .cfa-progress-label {
  color: #1f2937;
}

.cfa-progress-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.kv .v {
  font-size: 14px;
  font-weight: 400;
  letter-spacing: 0.2px;
  word-break: break-word;
}

.note {
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}
body.light-mode .note {
  color: #4b5563;
}
.warn {
  color: var(--bad);
  font-weight: 600;
}
.warn-warm {
  color: #ffb347;
  font-weight: 600;
}
body.light-mode .warn-warm {
  color: #b45309;
}

.scroll {
  overflow: auto;
  flex: 1 1 auto;
  min-height: 0;
}

.efa-progress {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 0;
}

.efa-progress-bar {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: rgba(122, 162, 255, 0.18);
  overflow: hidden;
}

.efa-progress-bar::after {
  content: "";
  position: absolute;
  top: 0;
  left: -40%;
  width: 40%;
  height: 100%;
  background: linear-gradient(
    90deg,
    rgba(122, 162, 255, 0) 0%,
    rgba(122, 162, 255, 0.6) 50%,
    rgba(122, 255, 199, 0.6) 75%,
    rgba(122, 255, 199, 0) 100%
  );
  animation: efaProgressSlide 1.6s ease-in-out infinite;
}

@keyframes efaProgressSlide {
  0% {
    left: -40%;
  }
  50% {
    left: 60%;
  }
  100% {
    left: 110%;
  }
}

table {
  width: auto;
  border-collapse: collapse;
  font-size: 13px;
  display: block;
  max-width: 100%;
}
th,
td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--table-row-border);
  vertical-align: top;
}
th {
  color: var(--table-head-text);
  font-weight: 650;
  font-size: 12px;
  letter-spacing: 0.25px;
  position: sticky;
  top: 0;
  background: var(--table-head-bg);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--table-head-border);
  z-index: 2;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th .sort {
  margin-left: 6px;
  font-size: 11px;
  opacity: 0.85;
}
th:hover {
  color: var(--table-head-text);
}
tr:hover td {
  background: var(--table-row-hover);
}
body.light-mode th {
  background: var(--table-head-bg) !important;
  color: var(--table-head-text) !important;
}
body.light-mode tr[style*="background: #1f2937"],
body.light-mode tr[style*="background:#1f2937"],
body.light-mode tr[style*="background: #0f172a"],
body.light-mode tr[style*="background:#0f172a"],
body.light-mode tr[style*="background: #111827"],
body.light-mode tr[style*="background:#111827"] {
  background: var(--table-head-bg) !important;
}
body.light-mode [style*="color:#e9ecf1"],
body.light-mode [style*="color: #e9ecf1"] {
  color: #111827 !important;
}
body.light-mode [style*="color: rgb(233, 236, 241)"] {
  color: #111827 !important;
}
body.light-mode [style*="color:#cfd6e8"],
body.light-mode [style*="color: #cfd6e8"] {
  color: #1f2937 !important;
}
body.light-mode [style*="color: rgb(207, 214, 232)"] {
  color: #1f2937 !important;
}
body.light-mode [style*="color:#e5e7eb"],
body.light-mode [style*="color: #e5e7eb"] {
  color: #111827 !important;
}
body.light-mode [style*="color: rgb(229, 231, 235)"] {
  color: #111827 !important;
}
body.light-mode [style*="color:#9ca3af"],
body.light-mode [style*="color: #9ca3af"] {
  color: #374151 !important;
}
body.light-mode [style*="color: rgb(156, 163, 175)"] {
  color: #374151 !important;
}
body.light-mode [style*="color:#b6bfd2"],
body.light-mode [style*="color: #b6bfd2"] {
  color: #374151 !important;
}
body.light-mode [style*="color: rgb(182, 191, 210)"] {
  color: #374151 !important;
}
body.light-mode [style*="color: rgb(182, 191, 210)"] {
  color: #374151 !important;
}
body.light-mode [style*="color:#7ab4ff"],
body.light-mode [style*="color: #7ab4ff"] {
  color: #1d4ed8 !important;
}
body.light-mode [style*="color: rgb(122, 180, 255)"] {
  color: #1d4ed8 !important;
}
body.light-mode [style*="color:#7affc7"],
body.light-mode [style*="color: #7affc7"] {
  color: #15803d !important;
}
body.light-mode [style*="color: rgb(122, 255, 199)"] {
  color: #15803d !important;
}
body.light-mode [style*="color:#ffb347"],
body.light-mode [style*="color: #ffb347"] {
  color: #b45309 !important;
}
body.light-mode [style*="color: rgb(255, 179, 71)"] {
  color: #b45309 !important;
}

.copy-hover-wrap {
  position: relative;
  display: block;
  max-width: 100%;
}

.table-copy-wrap {
  position: relative;
  display: block;
  max-width: 100%;
  width: 100%;
  overflow-x: auto;
  padding-right: 36px;
}

.copy-hover-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
  z-index: 5;
}

.copy-hover-wrap:hover .copy-hover-btn,
.copy-hover-wrap:focus-within .copy-hover-btn {
  opacity: 1;
  pointer-events: auto;
}

@media (hover: none) {
  .copy-hover-btn {
    opacity: 1;
    pointer-events: auto;
  }
}

.mono {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

.badge {
  display: inline-flex;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.2px;
  background: rgba(255, 255, 255, 0.06);
}
.badge.ok {
  border-color: rgba(122, 255, 199, 0.35);
  background: rgba(122, 255, 199, 0.1);
}
.badge.accent {
  border-color: rgba(122, 162, 255, 0.35);
  background: rgba(122, 162, 255, 0.1);
}

.tiny {
  font-size: 12px;
  color: var(--muted);
}
body.light-mode .tiny {
  color: #4b5563;
}

/* EFA variable list styling for better contrast */
#efaVarList {
  background: transparent; /* keep card background */
  color: var(--text);
  border-radius: 8px;
}
/* EFA variable grid layout */
#efaVarListContainer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px;
  align-content: flex-start;
}
.efa-var-row {
  color: var(--text);
  padding: 8px 12px !important;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  transition: all 0.15s ease;
}
.efa-var-row:hover {
  background: rgba(122, 162, 255, 0.08);
  border-color: rgba(122, 162, 255, 0.2);
}
.efa-var-row.selected {
  background: rgba(122, 162, 255, 0.25) !important;
  border-color: rgba(122, 162, 255, 0.5) !important;
  color: var(--text) !important;
  font-weight: 600;
}
.search {
  flex: 1 1 260px;
  max-width: 420px;
  min-width: 220px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.12);
  color: var(--text);
  outline: none;
}
.search:focus {
  border-color: rgba(122, 162, 255, 0.55);
}

.preview-controls {
  flex-wrap: nowrap;
}

.preview-hint {
  margin-bottom: 8px;
  line-height: 1.4;
}

@media (max-width: 900px) {
  .preview-controls {
    flex-wrap: wrap;
  }
}

.preview-flag-head,
.preview-flag-cell {
  text-align: center;
  width: 36px;
  min-width: 36px;
}

.preview-flag-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 1px solid rgba(249, 115, 22, 0.6);
  background: rgba(249, 115, 22, 0.16);
  color: #f97316;
  font-weight: 700;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
}

.preview-flag-btn.pending {
  background: rgba(249, 115, 22, 0.55);
  color: #fff;
}

body.light-mode .preview-flag-btn.pending {
  color: #111827;
}

.cleaning-actions {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.cleaning-actions-title {
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.3px;
  color: var(--muted);
  margin-bottom: 6px;
}

.cleaning-actions ul {
  margin: 0;
  padding-left: 18px;
}

.cleaning-actions li {
  font-size: 12px;
  color: var(--text);
  margin: 4px 0;
}

body.light-mode .cleaning-actions li {
  color: #111827;
}

.footer {
  padding: 10px 18px 26px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

th.num,
td.num {
  text-align: right;
}
th.center,
td.center {
  text-align: center;
}
th.left,
td.left {
  text-align: left;
}

/* Dragging: prevent selection */
.dragging {
  user-select: none !important;
  cursor: grabbing !important;
}

/* Report panel: force an opaque, readable card on the right side */
.reportPanel {
  background: #0f1724 !important;
  border: 1px solid rgba(255, 255, 255, 0.06) !important;
  box-shadow: var(--shadow) !important;
}

/* EFA panel full-height layout when expanded */
.frame#efaCard {
  display: flex;
  flex-direction: column;
}

.frame#efaCard:not(.collapsed) .bd {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.frame#efaCard.collapsed .bd {
  display: none;
}

.frame#efaCard #efaVarList {
  flex: 1 1 auto;
  min-height: 250px;
  max-height: none;
  height: auto;
}
/* CFA panel styling */
.frame#cfaCard:not(.collapsed) .bd {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.frame#cfaCard.collapsed .bd {
  display: none;
}

.frame#cfaCard.collapsed .hd .row > :not(#cfaBuildFromEfaBtn) {
  display: none !important;
}

.cfa-var-item {
  transition: all 0.15s ease;
}

.cfa-var-item:not([style*="pointer-events: none"]):hover {
  background: rgba(122, 180, 255, 0.8) !important;
  transform: translateX(2px);
}

.cfa-control-bar {
  transform: scale(0.7);
  transform-origin: top right;
}

#cfaCanvas {
  cursor: crosshair;
}
#cfaCanvas text {
  user-select: none;
  -webkit-user-select: none;
}
body.light-mode #cfaCanvasWrap {
  background: var(--cfa-canvas-bg) !important;
}
body.light-mode #cfaCanvas {
  background: transparent !important;
}
body.light-mode #cfaCanvas text {
  fill: #1f2937 !important;
}
body.light-mode #cfaCanvas line,
body.light-mode #cfaCanvas path {
  stroke: rgba(15, 23, 42, 0.65) !important;
}
body.light-mode #cfaCanvas .canvas-hit {
  stroke: transparent !important;
}
body.light-mode #cfaCanvas polygon {
  fill: rgba(15, 23, 42, 0.65) !important;
}
body.light-mode #cfaCanvas rect[data-type="latent"] {
  fill: rgba(37, 99, 235, 0.12) !important;
  stroke: #1d4ed8 !important;
}
body.light-mode #cfaCanvas rect[data-type="manifest"] {
  fill: rgba(15, 23, 42, 0.03) !important;
  stroke: rgba(15, 23, 42, 0.35) !important;
}

.cfa-delete-btn {
  cursor: pointer !important;
}

.cfa-delete-btn * {
  cursor: pointer !important;
}

.cfa-fl-table td,
.cfa-fl-table th {
  transition: background 0.15s ease;
}

.cfa-fl-split {
  display: flex;
  align-items: stretch;
  gap: 0;
  min-height: 220px;
  flex-wrap: nowrap;
}

.cfa-fl-left {
  flex: 0 0 var(--fl-left, 65%);
  min-width: 260px;
  max-width: 100%;
}

.cfa-fl-right {
  flex: 1 1 calc(100% - var(--fl-left, 65%));
  min-width: 240px;
  max-width: 100%;
}

.cfa-fl-divider {
  width: 8px;
  cursor: col-resize;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.18),
    rgba(255, 255, 255, 0.08)
  );
  border-left: 1px solid rgba(255, 255, 255, 0.06);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 6px;
  margin: 0 10px;
  touch-action: none;
  align-self: stretch;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}

.cfa-fl-divider:hover {
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.16),
    rgba(255, 255, 255, 0.06)
  );
}

.efa-output-split {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 16px;
  margin-top: 12px;
}

.efa-output-left {
  flex: 1 1 360px;
  min-width: 260px;
}

.efa-output-right {
  flex: 1 1 320px;
  min-width: 240px;
}

.efa-output-divider {
  width: 8px;
  align-self: stretch;
  margin: 0 8px;
  border-radius: 6px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.14),
    rgba(255, 255, 255, 0.05)
  );
  border-left: 1px solid rgba(255, 255, 255, 0.06);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
}

@media (max-width: 900px) {
  .efa-output-divider {
    display: none;
  }
}

.cfa-fl-row-hover td {
  background: rgba(122, 162, 255, 0.08) !important;
}

.cfa-fl-col-hover {
  background: rgba(122, 162, 255, 0.08) !important;
}
/* Structural modeling panel styling */
.frame#structCard:not(.collapsed) .bd {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.frame#structCard.collapsed .bd {
  display: none;
}

.struct-control-bar {
  transform: scale(0.7);
  transform-origin: top right;
}

.struct-control-bar .btn {
  display: flex;
  align-items: center;
  justify-content: center;
}

.struct-mode-btn.is-active {
  background: var(--tab-bg-active) !important;
  color: var(--tab-text-active) !important;
  border-color: var(--tab-border) !important;
}

#structCanvas {
  cursor: crosshair;
}

#structCanvas text {
  user-select: none;
  -webkit-user-select: none;
}

body.light-mode #structCanvasWrap {
  background: var(--cfa-canvas-bg) !important;
}

body.light-mode #structCanvas {
  background: transparent !important;
}

body.light-mode #structCanvas text {
  fill: #1f2937 !important;
}

body.light-mode #structCanvas line,
body.light-mode #structCanvas path {
  stroke: rgba(15, 23, 42, 0.65) !important;
}
body.light-mode #structCanvas .canvas-hit {
  stroke: transparent !important;
}

body.light-mode #structCanvas polygon {
  fill: rgba(15, 23, 42, 0.65) !important;
}

body.light-mode #structCanvas [data-type="latent"] {
  fill: rgba(37, 99, 235, 0.12) !important;
  stroke: #1d4ed8 !important;
}

body.light-mode #structCanvas [data-type="composite"] {
  fill: rgba(245, 158, 11, 0.14) !important;
  stroke: rgba(161, 98, 7, 0.7) !important;
}

body.light-mode #structCanvas [data-type="observed"] {
  fill: rgba(15, 23, 42, 0.04) !important;
  stroke: rgba(15, 23, 42, 0.35) !important;
}

body.light-mode #structCanvas [data-type="indicator"] {
  fill: rgba(15, 23, 42, 0.08) !important;
  stroke: rgba(15, 23, 42, 0.35) !important;
}

.struct-tab-btn {
  padding: 4px 8px;
  border: 1px solid var(--tab-border);
  border-radius: 3px;
  background: var(--tab-bg-inactive);
  color: var(--tab-text-inactive);
  cursor: pointer;
  font-size: 12px;
}

.struct-tab-btn.is-active {
  background: var(--tab-bg-active);
  color: var(--tab-text-active);
}

.report-tab-buttons,
.efa-tab-buttons,
.cfa-tab-buttons,
.struct-tab-buttons {
  position: sticky;
  top: 0;
  z-index: 4;
  background: var(--surface-1);
  padding: 6px 0 10px;
}
body.light-mode .report-tab-btn,
body.light-mode .efa-tab-btn,
body.light-mode .struct-tab-btn {
  background: var(--tab-bg-inactive) !important;
  color: var(--tab-text-inactive) !important;
  border-color: var(--tab-border) !important;
}
body.light-mode .report-tab-btn.is-active,
body.light-mode .efa-tab-btn.is-active,
body.light-mode .struct-tab-btn.is-active {
  background: var(--tab-bg-active) !important;
  color: var(--tab-text-active) !important;
}

body.light-mode .efa-type-filter,
body.light-mode .efa-estimator-btn,
body.light-mode .efa-extract-btn {
  background: #e5e7eb !important;
  color: #111827 !important;
  border-color: rgba(15, 23, 42, 0.18) !important;
}

body.light-mode .efa-type-filter.secondary,
body.light-mode .efa-estimator-btn.secondary,
body.light-mode .efa-extract-btn.secondary {
  background: #f1f5f9 !important;
  color: #475569 !important;
}
