/* Canvas Calculation Engine: fill panel, test view, formula editor. */

.epi-setup-panel {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--ps-line);
}

.epi-builder-shell {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: calc(100vh - var(--shell-header-height) - 24px);
}

.epi-builder-head,
.epi-table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border: 1px solid var(--ps-line);
  border-radius: var(--radius);
  background: var(--ps-panel);
  box-shadow: var(--shadow-tight);
}

.epi-builder-head h1 {
  margin: 2px 0 8px;
  font-size: 24px;
  line-height: 1.15;
}

.epi-head-actions,
.epi-form-actions,
.epi-preset-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.epi-head-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.epi-inline-feedback {
  width: fit-content;
  max-width: 100%;
  margin: 0;
  padding: 7px 10px;
  border: 1px solid rgba(36, 124, 138, 0.22);
  border-radius: 6px;
  background: var(--ps-teal-soft);
}

.epi-view-switch {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--ps-line);
  border-radius: 8px;
  background: var(--ps-surface-soft);
}

.epi-view-switch .btn {
  min-height: 34px;
  padding: 7px 10px;
  border-color: transparent;
  background: transparent;
}

.epi-view-switch .btn.active {
  border-color: rgba(36, 124, 138, 0.28);
  background: var(--ps-panel);
  color: var(--ps-teal-text);
  box-shadow: 0 4px 10px rgba(31, 41, 55, 0.08);
}

.epi-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.32);
}

.epi-save-modal {
  width: min(760px, calc(100vw - 48px));
  max-height: calc(100vh - 48px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  border: 1px solid var(--ps-line);
  border-radius: 10px;
  background: var(--ps-overlay);
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.24);
  overflow: hidden;
}

.epi-save-modal-head,
.epi-save-modal-foot {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  background: var(--ps-surface-soft);
}

.epi-save-modal-head {
  border-bottom: 1px solid var(--ps-line);
}

.epi-save-modal-foot {
  align-items: center;
  justify-content: flex-end;
  border-top: 1px solid var(--ps-line);
}

.epi-save-modal h2 {
  margin: 2px 0 5px;
  font-size: 20px;
}

.epi-save-modal p {
  margin: 0;
  color: var(--ps-muted);
  font-size: 12px;
  line-height: 1.45;
}

.epi-save-modal-body {
  display: grid;
  gap: 9px;
  padding: 16px 18px 18px;
  overflow: auto;
}

.epi-save-modal-body label {
  color: var(--ps-charcoal);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.epi-save-modal-body input,
.epi-save-modal-body textarea {
  width: 100%;
  border: 1px solid var(--ps-line);
  border-radius: var(--radius);
  background: var(--ps-input);
  color: var(--ps-ink);
  font: inherit;
  padding: 10px 11px;
}

.epi-save-modal-body textarea {
  min-height: 82px;
  resize: vertical;
}

.epi-save-mode-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.epi-save-mode {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 7px 10px;
  align-items: start;
  padding: 13px;
  border: 1px solid var(--ps-line);
  border-radius: var(--radius);
  background: var(--ps-panel);
  cursor: pointer;
}

.epi-save-mode:not(:has(input:checked)):hover {
  border-color: var(--ps-line-strong);
  background: var(--ps-surface-soft);
}

.epi-save-mode input {
  position: absolute;
  opacity: 0;
}

.epi-save-mode > span {
  grid-row: span 2;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--ps-sidebar-active);
  color: var(--ps-teal-text);
}

.epi-save-mode strong {
  color: var(--ps-ink);
  font-size: 13px;
}

.epi-save-mode small {
  color: var(--ps-muted);
  font-size: 11px;
  line-height: 1.4;
}

.epi-save-mode:has(input:checked) {
  border-color: var(--ps-orange);
  background: var(--ps-accent-soft);
  box-shadow: 0 0 0 3px rgba(217, 101, 50, 0.12);
}

.epi-save-mode:has(input:checked) > span {
  background: var(--ps-accent-soft);
  color: var(--ps-orange-text);
}

.epi-save-mode:has(input:focus-visible) {
  outline: 2px solid var(--ps-orange);
  outline-offset: 2px;
}

.epi-builder-controls {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 150px 160px 120px;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--ps-line);
  border-radius: var(--radius);
  background: var(--ps-panel);
  box-shadow: var(--shadow-tight);
}

.epi-builder-controls .filter-field {
  margin: 0;
}

.epi-template-action {
  display: flex;
  align-items: center;
  gap: 8px;
}

.epi-template-action .smart-select {
  width: 220px;
}

.epi-workspace {
  position: relative;
  display: grid;
  grid-template-columns: 280px minmax(520px, 1fr) 320px;
  gap: 12px;
  height: clamp(620px, calc(100vh - 128px), 1040px);
  align-items: stretch;
  overflow: hidden;
}

.epi-workspace.library-collapsed {
  grid-template-columns: 52px minmax(560px, 1fr) 320px;
}

.epi-workspace.inspector-collapsed {
  grid-template-columns: 280px minmax(560px, 1fr) 52px;
}

.epi-workspace.library-collapsed.inspector-collapsed {
  grid-template-columns: 52px minmax(620px, 1fr) 52px;
}

.epi-workspace.canvas-focus {
  grid-template-columns: minmax(0, 1fr);
}

.epi-workspace.canvas-focus > .epi-canvas-wrap {
  grid-column: 1 / -1;
  width: 100%;
}

.epi-workspace.canvas-focus .epi-library,
.epi-workspace.canvas-focus .epi-inspector {
  display: none;
}

/* ── Fill Series drawer ──────────────────────────────────────────── */
.epi-fill-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  height: 330px;
  background: var(--ps-panel);
  border-top: 0.5px solid var(--ps-line-strong);
  box-shadow: 0 -10px 28px rgba(31, 41, 55, 0.14);
  border-radius: var(--radius) var(--radius) 0 0;
  transform: translateY(100%);
  transition: transform 0.22s ease;
}

.epi-fill-panel.open {
  transform: translateY(0);
}

.epi-fill-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--ps-line);
}

.epi-fill-panel-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-size: 13px;
  color: var(--ps-ink);
}

.epi-fill-clear-all {
  flex: 0 0 auto;
  margin-left: auto;
  min-height: 30px;
  padding: 5px 9px;
  color: #9f3f1c;
  border-color: rgba(230, 94, 39, 0.28);
  background: #fff8f4;
  white-space: nowrap;
}

.epi-tech-inline-fill > .epi-fill-panel-title {
  flex-wrap: wrap;
}
.epi-tech-inline-fill .epi-fill-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex: 0 0 auto;
}
.epi-tech-inline-fill .epi-fill-actions .epi-fill-clear-all {
  margin-left: 0;
}
.epi-tech-inline-fill .epi-fill-nova-entry {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 11px;
  white-space: nowrap;
}

.epi-fill-panel-title strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.epi-fill-generated-badge {
  flex: 0 0 auto;
  white-space: nowrap;
}

.epi-fill-panel-body {
  display: flex;
  align-items: stretch;
  gap: 14px;
  flex: 1;
  min-height: 0;
  padding: 12px 14px;
}

.epi-fill-method-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 140px;
  flex: 0 0 140px;
}

.epi-fill-method-separator {
  height: 1px;
  margin: 3px 5px;
  background: var(--ps-line);
}

.epi-fill-method-btn {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--ps-line);
  border-radius: 999px;
  background: var(--ps-panel);
  color: var(--ps-charcoal);
  font-size: 12px;
  font-weight: 700;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
  transition:
    border-color 0.12s,
    background 0.12s,
    color 0.12s;
}

.epi-fill-method-btn:hover {
  border-color: var(--ps-teal);
  color: var(--ps-teal-text);
}

.epi-fill-method-btn.active {
  border-color: rgba(36, 124, 138, 0.28);
  background: rgba(36, 124, 138, 0.08);
  color: var(--ps-teal-text);
}

.epi-fill-params {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 0 0 38%;
  max-width: 38%;
  min-width: 280px;
  padding: 2px 14px;
  border-left: 1px solid var(--ps-line);
  border-right: 1px solid var(--ps-line);
  overflow-y: auto;
}

.epi-fill-field {
  display: grid;
  gap: 5px;
}

.epi-fill-field label {
  color: var(--ps-charcoal);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.epi-fill-field input,
.epi-fill-field select {
  width: 100%;
  min-height: 32px;
  padding: 6px 9px;
  border: 1px solid var(--ps-line);
  border-radius: 7px;
  background: var(--ps-input);
  color: var(--ps-ink);
  font-size: 12px;
  outline: none;
}

.epi-fill-field input:focus,
.epi-fill-field select:focus {
  border-color: var(--ps-teal);
  box-shadow: 0 0 0 3px rgba(36, 124, 138, 0.12);
}

.epi-fill-field input:disabled,
.epi-fill-field select:disabled {
  color: var(--ps-muted);
  background: rgba(148, 163, 184, .08);
  cursor: not-allowed;
}

.epi-fill-demo-intro p { margin: 0; }
.epi-fill-demo-intro > p:last-child { color: var(--ps-muted); font-size: 12px; line-height: 1.45; }
.epi-fill-demo-eyebrow { color: var(--ps-teal-text); font-size: 10px; font-weight: 800; letter-spacing: .08em; }
.epi-fill-demo-note { display: grid; gap: 3px; padding: 8px 9px; border-left: 3px solid rgba(36, 124, 138, .45); border-radius: 0 6px 6px 0; background: rgba(36, 124, 138, .05); color: var(--ps-muted); font-size: 11px; line-height: 1.4; }
.epi-fill-demo-note strong { color: var(--ps-charcoal); font-size: 11px; }
.epi-fill-upload-button { align-self: flex-start; min-height: 32px; }
.epi-fill-upload-file-row { display: flex; align-items: center; gap: 8px; min-height: 32px; }
.epi-fill-upload-file-row .epi-fill-upload-button { position: relative; overflow: hidden; }
.epi-fill-upload-file-row input[type="file"] { position: absolute; inset: 0; width: 100%; opacity: 0; cursor: pointer; }
.epi-fill-upload-file-row > span { overflow: hidden; color: var(--ps-muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.epi-fill-upload-clear { min-height: 28px; padding: 4px 7px; font-size: 11px; }
.epi-fill-upload-file-details { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 14px; margin: 0; padding: 7px 9px; border: 1px solid var(--ps-line); border-radius: 7px; background: rgba(148, 163, 184, .04); }
.epi-fill-upload-file-details div { min-width: 0; }
.epi-fill-upload-file-details dt { color: var(--ps-muted); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.epi-fill-upload-file-details dd { margin: 2px 0 0; overflow: hidden; color: var(--ps-charcoal); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.epi-fill-demo-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.epi-fill-upload-preview { border: 1px solid var(--ps-line); border-radius: 7px; overflow: hidden; font-size: 11px; }
.epi-fill-upload-preview > strong { display: block; padding: 7px 9px; color: var(--ps-charcoal); font-size: 10px; text-transform: uppercase; letter-spacing: .04em; }
.epi-fill-upload-preview > small { display: block; padding: 7px 9px 0; color: var(--ps-muted); font-size: 11px; }
.epi-fill-upload-preview table { width: 100%; border-collapse: collapse; }
.epi-fill-upload-preview th, .epi-fill-upload-preview td { padding: 5px 9px; border-top: 1px solid var(--ps-line); text-align: left; }
.epi-fill-upload-preview th { color: var(--ps-muted); font-size: 10px; text-transform: uppercase; }
.epi-fill-upload-preview td { color: var(--ps-muted); }
.epi-fill-demo-actions { justify-content: flex-end; }
.epi-fill-upload-errors { color: var(--ps-red); font-size: 11px; line-height: 1.4; }
.epi-fill-upload-errors p { margin: 0 0 3px; }
.epi-fill-upload-apply { display: flex; justify-content: flex-end; padding-top: 2px; }
.epi-fill-upload-ready { margin: 0; color: var(--ps-muted); font-size: 11px; font-weight: 600; }

.epi-fill-slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.epi-fill-slider-row input[type="range"] {
  flex: 1;
  min-height: auto;
  padding: 0;
  border: none;
  background: transparent;
}

.epi-fill-slider-row span {
  flex: 0 0 auto;
  min-width: 28px;
  text-align: right;
  font-size: 12px;
  font-weight: 700;
  color: var(--ps-charcoal);
}

.epi-fill-help {
  margin: 0;
  color: var(--ps-muted);
  font-size: 11px;
  line-height: 1.5;
}

.epi-fill-value-with-unit {
  display: flex;
  align-items: center;
  gap: 8px;
}

.epi-fill-value-with-unit input {
  flex: 1 1 auto;
  min-width: 0;
}
.epi-fill-value-with-unit span {
  flex: 0 0 auto;
  color: var(--ps-muted);
  font-size: 11px;
  font-weight: 700;
}
.epi-fill-shape-list {
  flex-direction: row;
  width: 100%;
  gap: 5px;
}
.epi-fill-shape-list .epi-fill-method-btn {
  justify-content: center;
  padding: 7px 8px;
  text-align: center;
}
.epi-fill-validation {
  color: var(--ps-red);
  font-weight: 600;
}

.epi-fill-stepwise {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.epi-fill-step-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.epi-fill-step-table th {
  padding: 0 8px 6px;
  color: var(--ps-muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-align: left;
}

.epi-fill-step-table td {
  padding: 3px 8px 3px 0;
  vertical-align: middle;
}

.epi-fill-step-table select,
.epi-fill-step-table input {
  width: 100%;
  min-height: 30px;
  padding: 5px 8px;
  border: 1px solid var(--ps-line);
  border-radius: 7px;
  background: var(--ps-input);
  color: var(--ps-ink);
  font-size: 12px;
  outline: none;
}

.epi-fill-step-table .btn-icon {
  width: 28px;
  min-height: 28px;
}

.epi-fill-add-step {
  align-self: flex-start;
}

.epi-fill-chart {
  position: relative;
  flex: 1 1 62%;
  width: auto;
  min-width: 360px;
  min-height: 0;
}

.epi-fill-chart-plot {
  width: 100%;
  height: 100%;
}

.epi-fill-chart-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 0 10px;
  color: var(--ps-muted);
  font-size: 11px;
  text-align: center;
}

.epi-fill-actions {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-end;
  gap: 8px;
  flex: 0 0 auto;
}

/* The inline Calculation Engine header keeps its two actions horizontal. */
.epi-tech-inline-fill > .epi-fill-panel-title {
  flex-wrap: nowrap;
}
.epi-tech-inline-fill > .epi-fill-panel-title strong {
  flex: 1 1 auto;
  min-width: 0;
}
.epi-tech-inline-fill .epi-fill-actions {
  flex-direction: row;
  flex-wrap: nowrap;
}

.epi-forecast-flow-shell {
  display: grid;
  grid-template-columns: 280px minmax(620px, 1fr) 320px;
  gap: 12px;
  height: clamp(620px, calc(100vh - 128px), 1040px);
  align-items: stretch;
}

.epi-stage-panel,
.epi-forecast-inspector {
  border: 1px solid var(--ps-line);
  border-radius: var(--radius);
  background: var(--ps-panel);
  box-shadow: var(--shadow-tight);
  overflow: hidden;
}

.epi-stage-form {
  border-bottom: 1px solid var(--ps-line);
}

.epi-stage-list {
  display: grid;
  gap: 8px;
  padding: 12px;
  max-height: calc(100% - 150px);
  overflow: auto;
}

.epi-stage-list-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--ps-line);
  border-radius: 7px;
  background: var(--ps-panel);
  color: var(--ps-ink);
  text-align: left;
  cursor: pointer;
}

.epi-stage-list-item strong {
  min-width: 0;
  overflow: hidden;
  font-size: 13.5px;
  line-height: 1.2;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.epi-stage-list-item small {
  color: var(--ps-muted);
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
}

.epi-stage-list-item.selected,
.epi-stage-list-item:hover {
  border-color: rgba(23, 126, 137, 0.45);
  background: rgba(23, 126, 137, 0.06);
}

.epi-wide-btn {
  width: calc(100% - 24px);
  margin: 0 12px 12px;
  justify-content: center;
}

.epi-forecast-flow-wrap {
  position: relative;
  border: 1px solid var(--ps-line);
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 1px 1px, rgba(23, 126, 137, 0.17) 1px, transparent 1.5px),
    linear-gradient(180deg, #fbfdff 0%, #f6fafc 100%);
  background-size:
    24px 24px,
    100% 100%;
  box-shadow: var(--shadow-tight);
  cursor: grab;
}

.epi-forecast-flow-canvas {
  position: relative;
  min-width: 100%;
  min-height: 100%;
  transform-origin: 0 0;
}

.epi-forecast-conn-layer {
  position: absolute;
  inset: 0;
  overflow: visible;
  pointer-events: none;
  z-index: 1;
}

.epi-forecast-conn {
  fill: none;
  stroke: rgba(23, 126, 137, 0.9);
  stroke-width: 2.8;
  stroke-linecap: round;
}

.epi-forecast-arrow-head {
  fill: rgba(23, 126, 137, 0.9);
}

.epi-stage-node {
  position: absolute;
  z-index: 2;
  width: 220px;
  min-height: 126px;
  padding: 13px;
  border: 2px solid;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.1);
  cursor: grab;
  overflow: hidden;
}

.epi-stage-node:active,
.epi-flow-comment:active {
  cursor: grabbing;
}

.epi-stage-node.selected {
  border-color: var(--ps-orange-text) !important;
  box-shadow:
    0 0 0 3px rgba(230, 94, 39, 0.16),
    0 18px 38px rgba(15, 23, 42, 0.12);
}

.epi-stage-node-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.epi-stage-node-head strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
}

.epi-stage-node p,
.epi-flow-comment p {
  margin: 10px 0 12px;
  color: var(--ps-muted);
  font-size: 12px;
  line-height: 1.35;
}

.epi-stage-connect {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--ps-line);
  border-radius: 7px;
  background: var(--ps-panel);
  color: var(--ps-muted);
  cursor: pointer;
}

.epi-stage-connect.active,
.epi-stage-connect:hover {
  color: var(--ps-teal-text);
  border-color: rgba(23, 126, 137, 0.45);
  background: rgba(23, 126, 137, 0.08);
}

.epi-stage-resize {
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  background:
    linear-gradient(
      135deg,
      transparent 52%,
      rgba(100, 116, 139, 0.36) 54%,
      rgba(100, 116, 139, 0.36) 60%,
      transparent 62%
    ),
    linear-gradient(
      135deg,
      transparent 68%,
      rgba(100, 116, 139, 0.36) 70%,
      rgba(100, 116, 139, 0.36) 76%,
      transparent 78%
    );
  cursor: nwse-resize;
}

.epi-stage-resize:hover {
  background:
    linear-gradient(
      135deg,
      transparent 52%,
      rgba(23, 126, 137, 0.72) 54%,
      rgba(23, 126, 137, 0.72) 60%,
      transparent 62%
    ),
    linear-gradient(
      135deg,
      transparent 68%,
      rgba(23, 126, 137, 0.72) 70%,
      rgba(23, 126, 137, 0.72) 76%,
      transparent 78%
    );
}

.epi-flow-comment {
  position: absolute;
  z-index: 3;
  width: 230px;
  min-height: 120px;
  padding: 12px;
  border: 1px solid rgba(245, 158, 11, 0.45);
  border-left: 4px solid #f59e0b;
  border-radius: 8px;
  background: #fffaf0;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.1);
  cursor: grab;
}

.epi-flow-comment.selected {
  border-color: var(--ps-orange-text);
  box-shadow:
    0 0 0 3px rgba(230, 94, 39, 0.16),
    0 12px 24px rgba(15, 23, 42, 0.12);
}

.epi-flow-comment div {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--ps-ink);
}

.epi-connection-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  margin: 6px 6px 0 0;
  padding: 6px 8px;
  border: 1px solid rgba(23, 126, 137, 0.28);
  border-radius: 999px;
  background: rgba(23, 126, 137, 0.07);
  color: var(--ps-teal-text);
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

.epi-library,
.epi-inspector,
.epi-table-shell {
  border: 1px solid var(--ps-line);
  border-radius: var(--radius);
  background: var(--ps-panel);
  box-shadow: var(--shadow-tight);
}

.epi-library,
.epi-inspector {
  overflow: hidden;
}

.epi-library {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.epi-library-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

.epi-library.collapsed,
.epi-inspector.collapsed {
  display: grid;
  place-items: stretch;
  min-width: 0;
  background: var(--ps-surface-soft);
}

.epi-panel-rail-btn {
  display: grid;
  place-items: center;
  gap: 8px;
  width: 100%;
  min-height: 100%;
  padding: 12px 6px;
  border: 0;
  background: transparent;
  color: var(--ps-muted);
  cursor: pointer;
}

.epi-panel-rail-btn span {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.epi-panel-rail-btn:hover {
  color: var(--ps-teal-text);
  background: var(--ps-sidebar-active);
}

.epi-panel-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.epi-output-apply-status {
  color: var(--ps-muted);
  font-size: 11px;
  white-space: nowrap;
}

.epi-output-apply-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 9px;
  border-radius: 7px;
  color: #9a6700;
  background: #fff7df;
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
}

.epi-output-apply-pill i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #f5b700;
}

.epi-output-display {
  display: grid;
  gap: 5px;
  margin: 8px 12px 10px;
  padding: 9px 10px;
  border: 1px solid var(--ps-line);
  border-radius: 8px;
}

.epi-output-display > strong {
  font-size: 11px;
  line-height: 1.2;
}

.epi-output-display > small {
  color: var(--ps-muted);
  font-size: 9.5px;
  line-height: 1.3;
}

.epi-output-display label {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  align-items: start;
  gap: 7px;
  padding: 2px 0;
  cursor: pointer;
}

.epi-output-display label > input[type="radio"],
.epi-output-display label > input[type="checkbox"] {
  box-sizing: border-box;
  width: 16px;
  min-width: 16px;
  height: 16px;
  min-height: 16px;
  margin: 2px 0 0;
  padding: 0;
  accent-color: var(--ps-teal);
}

.epi-output-display label span {
  display: grid;
  min-width: 0;
  gap: 1px;
}

.epi-output-display label b {
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
}

.epi-output-display label small {
  color: var(--ps-muted);
  font-size: 9.5px;
  line-height: 1.25;
}

.epi-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--ps-line);
  background: var(--ps-surface-soft);
}

.epi-panel-head h3 {
  margin: 0 0 3px;
  font-size: 12.5px;
}

.epi-panel-head p,
.epi-help {
  margin: 0;
  color: var(--ps-muted);
  font-size: 10px;
  line-height: 1.45;
}

.epi-library-search {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  border-bottom: 1px solid var(--ps-line);
  color: var(--ps-muted);
  background: var(--ps-panel);
}

.epi-library-search input {
  width: 100%;
  min-height: 30px;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ps-ink);
  font-size: 11px;
}

.epi-mini-form {
  display: grid;
  gap: 9px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--ps-line);
  background: var(--ps-panel);
}

.epi-mini-form label,
.epi-inspector-form label {
  color: var(--ps-charcoal);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.epi-mini-form input,
.epi-mini-form select,
.epi-mini-form textarea,
.epi-inspector-form input,
.epi-inspector-form select,
.epi-inspector-form textarea,
.epi-forecast-table input {
  width: 100%;
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid var(--ps-line);
  border-radius: 7px;
  background: var(--ps-input);
  color: var(--ps-ink);
  font-size: 12px;
  outline: none;
}

.epi-mini-form textarea,
.epi-inspector-form textarea {
  min-height: 84px;
  resize: vertical;
}

.epi-mini-form input:focus,
.epi-mini-form select:focus,
.epi-mini-form textarea:focus,
.epi-inspector-form input:focus,
.epi-inspector-form select:focus,
.epi-inspector-form textarea:focus,
.epi-forecast-table input:focus {
  border-color: var(--ps-teal);
  box-shadow: 0 0 0 3px rgba(36, 124, 138, 0.12);
}

.epi-form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
}

.epi-form-field {
  display: grid;
  gap: 5px;
}

.epi-color-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.epi-swatch input {
  position: absolute;
  opacity: 0;
}

.epi-swatch span {
  display: block;
  width: 22px;
  height: 22px;
  border: 2px solid transparent;
  border-radius: 50%;
}

.epi-swatch input:checked + span {
  border-color: var(--ps-ink);
}

.epi-library-empty,
.epi-inspector-empty,
.epi-empty-canvas {
  display: grid;
  place-items: center;
  gap: 8px;
  padding: 24px 16px;
  color: var(--ps-muted);
  text-align: center;
  font-size: 11px;
}

.epi-library-empty strong,
.epi-inspector-empty strong,
.epi-empty-canvas h3 {
  color: var(--ps-charcoal);
  font-size: 12.5px;
}

.epi-empty-canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.epi-empty-canvas p {
  max-width: 310px;
  margin: 0;
}

.epi-category {
  border-bottom: 1px solid var(--ps-line);
  background: color-mix(in srgb, var(--epi-stage-color, #177e89) 4%, transparent);
}

.epi-category:has(.epi-card-chip[draggable="true"]):hover {
  background: rgba(23, 126, 137, 0.025);
}

.epi-category-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  padding: 8px 9px 7px;
}

.epi-category-head strong {
  min-width: 0;
  overflow: hidden;
  color: var(--ps-charcoal);
  font-size: 12px;
  line-height: 1.2;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.epi-category-head small {
  color: var(--ps-muted);
  font-size: 10px;
  font-weight: 800;
}

.epi-category-actions {
  grid-column: 2 / 4;
  display: flex;
  gap: 6px;
  justify-content: flex-start;
  margin-top: 6px;
}

.epi-category-actions .btn-icon {
  width: 30px;
  min-height: 30px;
}

.epi-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.epi-card-list {
  display: grid;
  gap: 5px;
  padding: 0 9px 10px;
}

.epi-card-chip {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 6px 7px;
  border: 1px solid var(--ps-line);
  border-left: 4px solid var(--ps-teal);
  border-radius: 7px;
  background: var(--ps-surface-soft);
  cursor: grab;
}

.epi-card-chip span {
  min-width: 0;
  display: -webkit-box;
  overflow: hidden;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: normal;
  -webkit-box-orient: vertical;
  line-clamp: 2;
  -webkit-line-clamp: 2;
}

.epi-card-chip small {
  color: var(--ps-muted);
  font-size: 8.5px;
  font-weight: 800;
  text-transform: uppercase;
}

.epi-card-chip button {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ps-muted);
}

.epi-card-chip button:hover {
  background: var(--ps-line);
  color: var(--ps-red);
}

.epi-canvas-wrap,
.epi-test-canvas-wrap {
  position: relative;
  min-width: 0;
  height: 100%;
  overflow: auto;
  scrollbar-width: none;
  border: 1px solid var(--ps-line);
  border-radius: var(--radius);
  background:
    radial-gradient(circle, rgba(36, 124, 138, 0.18) 1px, transparent 1px), linear-gradient(180deg, var(--ps-raised), #f4f7fb);
  background-size:
    26px 26px,
    auto;
  box-shadow: var(--shadow-tight);
  cursor: grab;
  overscroll-behavior: contain;
}

.epi-canvas-wrap::-webkit-scrollbar,
.epi-test-canvas-wrap::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.epi-canvas-wrap.panning,
.epi-test-canvas-wrap.panning {
  cursor: grabbing;
}

.epi-canvas-zoom {
  position: relative;
  cursor: inherit;
}

.epi-canvas-tools {
  position: sticky;
  top: 12px;
  left: 12px;
  z-index: 24;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px;
  margin: 12px 0 0 12px;
  border: 1px solid rgba(200, 208, 218, 0.86);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 8px 18px rgba(31, 41, 55, 0.08);
  backdrop-filter: blur(6px);
  cursor: default;
}

.epi-canvas-tools .btn {
  width: 32px;
  height: 32px;
  background: transparent;
}

.epi-canvas-tools .btn.active {
  border-color: rgba(36, 124, 138, 0.28);
  background: rgba(36, 124, 138, 0.08);
  color: var(--ps-teal-text);
}

.epi-canvas {
  position: relative;
  transform-origin: 0 0;
  cursor: inherit;
  /* width and height driven by inline style from epiConnLayerSize() */
}

.epi-canvas-wrap.panning .epi-canvas-zoom,
.epi-canvas-wrap.panning .epi-canvas,
.epi-test-canvas-wrap.panning .epi-canvas-zoom,
.epi-test-canvas-wrap.panning .epi-canvas {
  cursor: grabbing;
}

.epi-conn-layer {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 30;
  pointer-events: none;
  overflow: visible;
}

/* ── Minimap ─────────────────────────────────────────────────────── */
.epi-minimap-cluster {
  position: absolute;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  cursor: default;
}

.epi-canvas-test-btn {
  min-height: 34px;
  padding: 7px 10px;
  border-color: rgba(36, 124, 138, 0.28);
  background: rgba(255, 255, 255, 0.94);
  color: var(--ps-teal-dark);
  box-shadow: 0 10px 24px rgba(31, 41, 55, 0.1);
  white-space: nowrap;
  backdrop-filter: blur(8px);
}

.epi-canvas-test-btn:hover {
  border-color: rgba(36, 124, 138, 0.46);
  background: var(--ps-panel);
  color: var(--ps-teal-text);
}

.epi-minimap {
  position: absolute;
  width: 200px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--ps-line);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(31, 41, 55, 0.12);
  cursor: pointer;
  overflow: hidden;
  z-index: 20;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
  padding: 6px 7px 7px;
  backdrop-filter: blur(8px);
}

.epi-minimap-cluster .epi-minimap {
  position: relative;
  flex: 0 0 200px;
}

.epi-minimap:hover {
  border-color: rgba(36, 124, 138, 0.36);
  box-shadow: 0 12px 26px rgba(31, 41, 55, 0.16);
}

.epi-mm-label {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--ps-muted);
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 5px;
}

.epi-mm-canvas {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(221, 227, 234, 0.82);
  border-radius: 5px;
  background:
    radial-gradient(circle, rgba(36, 124, 138, 0.12) 1px, transparent 1px), linear-gradient(180deg, var(--ps-raised), #f4f7fb);
  background-size:
    10px 10px,
    auto;
}

.epi-mm-cat {
  position: absolute;
  border: 1px solid;
  border-radius: 4px;
  opacity: 0.84;
}

.epi-mm-viewport {
  position: absolute;
  border: 1.5px solid var(--ps-teal);
  border-radius: 3px;
  background: rgba(36, 124, 138, 0.08);
  pointer-events: none;
  box-shadow: 0 0 0 600px rgba(255, 255, 255, 0.36);
}

/* ── Category containers ─────────────────────────────────────────── */
.epi-cat-container {
  position: absolute;
  border: 2px solid;
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.07);
  overflow: visible;
  z-index: 2;
}

.epi-cat-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  height: 44px;
  cursor: grab;
  user-select: none;
  border-bottom: 1px solid rgba(0, 0, 0, 0.07);
  border-radius: 8px 8px 0 0;
  background: color-mix(in srgb, var(--epi-stage-color, #177e89) 12%, var(--ps-mix-base));
}

.epi-cat-header:active {
  cursor: grabbing;
}

.epi-cat-container.collapsed .epi-cat-header {
  border-bottom: none;
  border-radius: 8px;
}

.epi-cat-header strong {
  flex: 1;
  font-size: 12px;
  font-weight: 600;
  color: var(--ps-charcoal);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.epi-cat-header small {
  font-size: 11px;
  color: var(--ps-muted);
  flex-shrink: 0;
}

.epi-cat-collapse-btn {
  flex-shrink: 0;
  opacity: 0.55;
}

.epi-cat-collapse-btn:hover {
  opacity: 1;
}

.epi-cat-body {
  position: relative;
  padding: 16px;
  background: color-mix(in srgb, var(--epi-stage-color, #177e89) 6%, rgba(255, 255, 255, 0.86));
}

.epi-cat-conn-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

.epi-cat-conn,
.epi-cat-conn-underlay {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.epi-cat-conn {
  stroke: #007481;
  stroke-width: 2.4;
  opacity: 0.9;
}

.epi-cat-conn-underlay {
  stroke: rgba(255, 255, 255, 0.96);
  stroke-width: 5;
}

.epi-cat-conn.epi-segment-stem {
  stroke: var(--ps-purple);
}

.epi-conn {
  fill: none;
  stroke: #007481;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  opacity: 1;
  filter: none;
}

.epi-conn-underlay {
  fill: none;
  stroke: var(--ps-canvas);
  stroke-width: 5.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.epi-conn.epi-segment-stem {
  stroke: var(--ps-purple);
  stroke-width: 2.6;
  stroke-dasharray: none;
  filter: none;
}

.epi-conn.epi-formula-conn {
  stroke: #007481;
  stroke-width: 2.6;
  stroke-dasharray: none;
  filter: none;
}

/* Hover isolation: dim all connection groups, then restore lit ones */
.epi-canvas.epi-conn-dimmed g,
.epi-test-canvas.epi-conn-dimmed g {
  opacity: 0.08;
  transition: opacity 0.12s ease;
}

.epi-canvas.epi-conn-dimmed g.epi-conn-lit,
.epi-test-canvas.epi-conn-dimmed g.epi-conn-lit {
  opacity: 1;
}

.epi-node {
  position: absolute;
  z-index: 2;
  width: 188px;
  height: 106px;
  min-height: 106px;
  border: 1px solid var(--ps-line-strong);
  border-radius: var(--radius);
  background: var(--ps-panel);
  box-shadow: var(--shadow-tight);
  cursor: move;
  user-select: none;
}

.epi-node.selected {
  border-color: var(--ps-orange);
  box-shadow:
    0 0 0 3px rgba(217, 101, 50, 0.18),
    var(--shadow-soft);
}

.epi-node.calculated .epi-node-body,
.epi-node.output .epi-node-body {
  background: #f4fbf8;
}

.epi-node.split .epi-node-body {
  background: var(--ps-row-section);
}

.epi-node-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 2px solid var(--ps-teal);
}

.epi-node-head strong {
  min-width: 0;
  display: -webkit-box;
  overflow: hidden;
  font-size: 11px;
  line-height: 1.18;
  text-overflow: ellipsis;
  white-space: normal;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.epi-node-head small {
  color: var(--ps-muted);
  font-size: 8px;
  font-weight: 800;
  text-transform: uppercase;
}

.epi-node-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.epi-node-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  color: var(--ps-muted);
  font-size: 10px;
}

.epi-node-body.segments {
  justify-content: flex-start;
  padding: 8px 10px 9px;
}

.epi-comment-node {
  min-height: 118px;
  border-left: 4px solid #f59e0b;
  background: #fffaf0;
}

.epi-comment-node-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px 8px;
  border-bottom: 1px solid rgba(245, 158, 11, 0.25);
}

.epi-comment-node-head strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.epi-comment-node p {
  margin: 9px 10px 10px;
  color: var(--ps-muted);
  font-size: 11px;
  line-height: 1.35;
}

.epi-test-shell {
  display: grid;
  grid-template-rows: auto minmax(520px, 1fr);
  gap: 10px;
  min-height: clamp(660px, calc(100vh - 128px), 1080px);
}

.epi-test-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 13px 16px;
  border: 1px solid var(--ps-line);
  border-radius: var(--radius);
  background: var(--ps-panel);
  box-shadow: var(--shadow-tight);
}

.epi-test-toolbar h3 {
  margin: 0 0 4px;
  font-size: 15px;
}

.epi-test-toolbar p {
  margin: 0;
  color: var(--ps-muted);
  font-size: 12px;
}

.epi-test-actions {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.epi-test-actions label {
  display: grid;
  gap: 4px;
  color: var(--ps-muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.epi-test-actions select {
  min-width: 132px;
  min-height: 36px;
  padding: 7px 9px;
  border: 1px solid var(--ps-line);
  border-radius: 7px;
  background: var(--ps-input);
  color: var(--ps-ink);
  font-size: 12px;
}

.epi-test-actions > .btn {
  min-height: 36px;
}

.epi-test-actions > .btn-icon {
  width: 32px;
  min-height: 32px;
  padding: 0;
}

.epi-test-actions .epi-tech-minimap {
  flex: 0 0 162px;
  width: 162px;
  margin-left: 8px;
}

.epi-test-actions .epi-business-tool-divider {
  margin-left: 0;
}

.epi-test-flow-scroll {
  position: relative;
  min-width: 0;
  min-height: 500px;
  overflow: auto;
  border: 1px solid var(--ps-line);
  border-radius: 10px;
  background-color: var(--ps-canvas);
  background-image: radial-gradient(circle, rgba(91, 112, 140, 0.12) 1px, transparent 1px);
  background-size: 20px 20px;
}

.epi-test-flow-canvas {
  position: relative;
  min-width: 100%;
  min-height: 100%;
  transform-origin: top left;
}

.epi-test-flow-stage {
  position: absolute;
  /* Keep the shell below the shared SVG; its positioned cards remain above. */
  box-sizing: border-box;
  overflow: visible;
  border: 1px solid color-mix(in srgb, var(--stage-color) 52%, #d7dee8);
  border-radius: 7px;
  background: color-mix(in srgb, var(--stage-color) 5%, var(--ps-mix-base));
  box-shadow: 0 3px 10px rgba(15, 23, 42, 0.035);
}

.epi-test-flow-stage-head {
  position: relative;
  z-index: 4;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  gap: 5px;
  align-items: center;
  min-height: 34px;
  padding: 5px 7px;
  border-bottom: 1px solid color-mix(in srgb, var(--stage-color) 22%, #e2e8f0);
  border-radius: 6px 6px 0 0;
  color: color-mix(in srgb, var(--stage-color) 80%, #1f2937);
  background: color-mix(in srgb, var(--stage-color) 9%, var(--ps-mix-base));
}

.epi-test-flow-stage-head > span {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  color: #fff;
  background: var(--stage-color);
}

.epi-test-flow-stage-head strong {
  overflow: hidden;
  font-size: 10.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.epi-test-flow-stage-head small {
  color: color-mix(in srgb, var(--stage-color) 65%, #64748b);
  font-size: 7.5px;
  font-weight: 800;
}

.epi-test-flow-card-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.epi-test-flow-card {
  position: absolute;
  z-index: 6;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, auto) 30px;
  align-content: center;
  gap: 7px;
  box-sizing: border-box;
  min-width: 0;
  padding: 5px 6px;
  overflow: hidden;
  border: 1px solid var(--ps-line);
  border-radius: 5px;
  background: var(--ps-panel);
  box-shadow: 0 2px 5px rgba(15, 23, 42, 0.045);
  pointer-events: auto;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    transform 0.15s ease;
}

.epi-test-flow-card.epi-inter-stage-participant {
  border-width: 2px;
  border-color: var(--stage-color);
}

.epi-test-flow-card:has(.epi-test-inline-split) {
  grid-template-columns: minmax(100px, 1fr) auto;
  grid-template-rows: 1fr;
  align-items: center;
  gap: 8px;
}

.epi-test-flow-card:has(.epi-test-transition-status),
.epi-test-flow-card:has(.epi-test-persistence-result),
.epi-test-flow-card:has(.epi-test-persistence-status) {
  grid-template-rows: auto minmax(0, 1fr);
  align-content: start;
}

.epi-test-flow-card.active-input,
.epi-test-flow-card:focus-within {
  z-index: 7;
  border-color: var(--ps-blue);
  background: linear-gradient(145deg, var(--ps-input) 0%, #eef5ff 52%, #dbeafe 100%);
  box-shadow:
    0 0 0 2px rgba(37, 99, 235, 0.2),
    0 8px 18px rgba(37, 99, 235, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  transform: translateY(-1px);
}

.epi-test-flow-card.active-input .epi-test-inline-input,
.epi-test-flow-card:focus-within .epi-test-inline-input {
  border-color: var(--ps-blue);
  color: #173f8f;
  background: #eff6ff;
  box-shadow:
    0 0 0 2px rgba(37, 99, 235, 0.13),
    inset 0 1px 2px rgba(37, 99, 235, 0.08);
}

.epi-test-flow-card-title {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  width: 100%;
}

.epi-test-flow-card-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  color: color-mix(in srgb, var(--stage-color) 78%, #334155);
}

.epi-test-flow-card-title strong {
  display: -webkit-box;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  color: var(--ps-charcoal);
  font-size: 9px;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: normal;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.epi-test-flow-card-title .epi-business-type {
  flex: 0 0 auto;
  margin-left: auto;
  max-width: 52px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 6.5px;
}

.epi-test-inline-input,
.epi-test-inline-result {
  justify-self: stretch;
  box-sizing: border-box;
  width: 100%;
  height: 28px;
  padding: 4px 5px;
  border: 1px solid var(--ps-line);
  border-radius: 5px;
  background: var(--ps-raised);
  color: var(--ps-charcoal);
  font: inherit;
  font-size: 8.5px;
  font-weight: 850;
  text-align: right;
  outline: none;
}

.epi-test-inline-input:focus {
  border-color: var(--stage-color);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--stage-color) 15%, transparent);
}

.epi-test-inline-result {
  display: grid;
  place-items: center end;
  width: auto;
  min-width: 44px;
  color: #475569;
}

.epi-test-inline-result.ready {
  color: var(--ps-teal-dark);
  background: #eef9f7;
}

.epi-test-inline-result.error {
  color: var(--ps-red);
  background: #fff2f2;
}

.epi-test-transition-status,
.epi-test-persistence-status,
.epi-test-persistence-result {
  display: grid;
  gap: 5px;
  min-width: 0;
  color: #52677a;
  font-size: 8px;
}
.epi-test-transition-status { align-content: center; color: #7155b7; }
.epi-test-transition-status strong { overflow: hidden; color: #6243ad; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.epi-test-transition-status small { color: var(--ps-muted); font-size: 8px; }
.epi-test-transition-status small svg { vertical-align: -2px; }
.epi-test-persistence-status { align-content: center; }
.epi-test-persistence-status strong { color: var(--ps-muted); font-size: 9px; }
.epi-test-persistence-status.error strong { color: var(--ps-red); }
.epi-test-persistence-result { align-content: start; }
.epi-test-persistence-total,
.epi-test-persistence-lots { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 7px; }
.epi-test-persistence-total { padding-bottom: 5px; border-bottom: 1px solid var(--ps-line); }
.epi-test-persistence-total span,
.epi-test-persistence-lots span { color: var(--ps-muted); }
.epi-test-persistence-total b { color: #0f6f7b; font-size: 9px; text-align: right; }
.epi-test-persistence-lots div { display: contents; }
.epi-test-persistence-lots b { color: var(--ps-charcoal); font-size: 8.5px; font-weight: 750; text-align: right; }

.epi-test-inline-split {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 7px;
  max-width: 100%;
  overflow-x: auto;
}

.epi-test-inline-split label {
  display: flex;
  align-items: center;
  gap: 2px;
  color: var(--ps-muted);
  flex: 0 0 auto;
  font-size: 7px;
  font-weight: 800;
}

.epi-test-inline-split label span {
  display: block;
  max-width: 44px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.epi-test-inline-split input {
  box-sizing: border-box;
  width: 44px;
  height: 24px;
  padding: 3px;
  border: 1px solid var(--ps-line);
  border-radius: 4px;
  color: var(--ps-charcoal);
  background: var(--ps-raised);
  font-size: 7.5px;
  font-weight: 800;
  text-align: right;
  outline: none;
}

.epi-test-canvas-wrap {
  min-height: 0;
}

.epi-test-cat .epi-cat-header {
  cursor: default;
}

.epi-test-node {
  min-height: 122px;
  cursor: default;
}

.epi-test-node .epi-node-body {
  display: grid;
  align-items: stretch;
  gap: 7px;
  padding: 8px 9px 10px;
}

.epi-test-node .epi-node-body.segments {
  display: grid;
  justify-content: stretch;
}

.epi-test-input-row,
.epi-test-segment-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px;
  align-items: center;
  gap: 6px;
  color: var(--ps-muted);
  font-size: 10px;
  font-weight: 800;
}

.epi-test-input-row input,
.epi-test-segment-input input {
  min-width: 0;
  height: 30px;
  padding: 5px 7px;
  border: 1px solid var(--ps-line);
  border-radius: 6px;
  background: var(--ps-input);
  color: var(--ps-ink);
  font-size: 12px;
  text-align: right;
  outline: none;
}

.epi-test-input-row input:focus,
.epi-test-segment-input input:focus,
.epi-test-actions select:focus {
  border-color: var(--ps-teal);
  box-shadow: 0 0 0 3px rgba(36, 124, 138, 0.12);
}

.epi-test-result,
.epi-test-readout,
.epi-test-split-total {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 30px;
  padding: 6px 7px;
  border: 1px solid var(--ps-line);
  border-radius: 7px;
  background: var(--ps-raised);
  color: var(--ps-muted);
  font-size: 10px;
  font-weight: 800;
}

.epi-test-result.ready,
.epi-test-readout {
  background: var(--ps-row-calc);
  color: var(--ps-charcoal);
}

.epi-test-readout strong,
.epi-test-result strong,
.epi-test-split-total strong {
  color: var(--ps-charcoal);
  font-size: 12px;
  font-weight: 900;
}

.epi-test-readout.error {
  border-color: rgba(220, 38, 38, 0.28);
  background: rgba(220, 38, 38, 0.06);
  color: var(--ps-red);
}

.epi-test-readout.error strong {
  color: var(--ps-red);
}

.epi-test-formula {
  display: block;
  max-width: 100%;
  overflow: hidden;
  color: var(--ps-muted);
  font-size: 9.5px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.epi-test-segment-list {
  display: grid;
  gap: 5px;
}

.epi-test-split-total.ok {
  border-color: rgba(14, 159, 110, 0.28);
  background: rgba(14, 159, 110, 0.08);
}

.epi-test-split-total.ok strong {
  color: var(--ps-green);
}

.epi-test-split-total.bad {
  border-color: rgba(220, 38, 38, 0.26);
  background: rgba(220, 38, 38, 0.06);
}

.epi-test-split-total.bad strong {
  color: var(--ps-red);
}

.epi-test-segment-node {
  cursor: default;
  pointer-events: none;
}

.epi-test-segment-node small {
  color: var(--ps-charcoal);
}

.epi-port {
  position: absolute;
  left: 50%;
  z-index: 8;
  width: 15px;
  height: 15px;
  padding: 0;
  border: 2px solid #13727d;
  border-radius: 50%;
  background: var(--ps-panel);
  transform: translateX(-50%);
  box-shadow:
    0 0 0 3px rgba(255, 255, 255, 0.95),
    0 1px 3px rgba(15, 23, 42, 0.18);
}

.epi-port.in {
  top: -8px;
}

.epi-port.out {
  bottom: -8px;
}

.epi-port:hover {
  border-color: var(--ps-orange);
  background: var(--ps-orange);
}

.epi-segment-node {
  position: absolute;
  z-index: 2;
  display: grid;
  gap: 2px;
  width: 104px;
  min-height: 56px;
  padding: 8px 10px;
  border: 1px solid rgba(109, 91, 208, 0.28);
  border-radius: var(--radius);
  background: #fbfaff;
  color: var(--ps-purple);
  box-shadow: var(--shadow-tight);
  text-align: left;
  cursor: crosshair;
}

.epi-segment-node:hover {
  border-color: rgba(109, 91, 208, 0.6);
  background: #f5f1ff;
  box-shadow:
    0 0 0 3px rgba(109, 91, 208, 0.11),
    var(--shadow-tight);
}

.epi-segment-node span {
  overflow: hidden;
  color: var(--ps-purple);
  font-size: 12px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.epi-segment-node small {
  color: #897be0;
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
}

.epi-inspector-form {
  display: grid;
  gap: 8px;
  padding: 10px;
  max-height: calc(100vh - 330px);
  overflow: auto;
}

.epi-inspector-section {
  border: 1px solid var(--ps-line);
  border-radius: 8px;
  background: var(--ps-panel);
  overflow: hidden;
}

.epi-section-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 38px;
  padding: 9px 10px;
  border: 0;
  border-bottom: 1px solid transparent;
  background: var(--ps-surface-soft);
  color: var(--ps-charcoal);
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.epi-section-toggle span {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 7px;
}

.epi-section-toggle:hover {
  color: var(--ps-teal-text);
}

.epi-inspector-section.open .epi-section-toggle {
  border-bottom-color: var(--ps-line);
}

.epi-section-body {
  display: grid;
  gap: 9px;
  padding: 10px;
}

.epi-variable-list {
  display: grid;
  gap: 8px;
}

.epi-variable-group {
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--ps-line);
  border-radius: 7px;
  background: var(--ps-surface-soft);
}

.epi-variable-group-title {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--ps-muted);
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.epi-variable-group-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.epi-variable-list button {
  max-width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--ps-line);
  border-radius: 999px;
  background: var(--ps-panel);
  color: var(--ps-charcoal);
  font-size: 11px;
  font-weight: 700;
}

.epi-variable-list button:hover {
  border-color: rgba(23, 126, 137, 0.34);
  color: var(--ps-teal-text);
  background: #f7fbfb;
}

.epi-variable-list span {
  color: var(--ps-muted);
  font-size: 11px;
}

.epi-segment-list {
  display: grid;
  gap: 6px;
}

.epi-connect-box {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--ps-line);
  border-radius: 7px;
  background: var(--ps-surface-soft);
}

.epi-connect-box.active {
  border-color: rgba(36, 124, 138, 0.35);
  background: rgba(36, 124, 138, 0.08);
}

.epi-connect-box span {
  color: var(--ps-muted);
  font-size: 11px;
  line-height: 1.4;
}

.epi-connect-box strong {
  color: var(--ps-charcoal);
}

.epi-validation-note {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  border: 1px solid rgba(220, 38, 38, 0.22);
  border-radius: 7px;
  background: rgba(220, 38, 38, 0.06);
  color: var(--ps-red);
  font-size: 11px;
  font-weight: 700;
}

.epi-validation-note.ok {
  border-color: rgba(14, 159, 110, 0.24);
  background: rgba(14, 159, 110, 0.07);
  color: var(--ps-green);
}

.epi-segment-editor {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) auto auto;
  gap: 6px;
  align-items: center;
  min-height: 34px;
}
.epi-segment-drag {
  display: grid;
  place-items: center;
  color: #8090a3;
}
.epi-segment-editor small {
  padding: 2px 4px;
  border-radius: 3px;
  color: #0d6971;
  background: #e7f7f8;
  font-size: 7.5px;
  font-weight: 900;
}
.epi-forecast-table tr.epi-table-split-focus td {
  background: rgba(23, 126, 137, 0.1) !important;
  transition: background 0.25s ease;
}

.epi-table-shell {
  height: calc(100vh - 126px);
  min-height: 560px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
}

.epi-output-shell {
  min-height: clamp(620px, calc(100vh - 128px), 1040px);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.epi-table-toolbar {
  border: 0;
  border-bottom: 1px solid var(--ps-line);
  border-radius: 0;
  box-shadow: none;
}

.epi-table-toolbar h3 {
  margin: 0 0 4px;
  font-size: 13.5px;
}

.epi-table-toolbar p {
  margin: 0;
  color: var(--ps-muted);
  font-size: 11px;
}

.epi-table-header-copy {
  flex: 1 1 auto;
  min-width: 0;
}
.epi-table-header-actions {
  display: flex;
  flex: 0 1 auto;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}
.epi-table-toolbar .epi-table-header-action {
  min-height: 33px;
  padding: 5px 9px;
  gap: 6px;
  border-radius: 6px;
  font-size: 11px;
  line-height: 1;
  white-space: nowrap;
}
.epi-table-toolbar .epi-table-header-action svg {
  width: 14px;
  height: 14px;
}
.epi-table-toolbar .epi-table-apply-output {
  border-color: #79b6bc;
  background: #edf8f8;
  color: #176f79;
  box-shadow: none;
}
.epi-table-toolbar .epi-table-apply-output:hover:not(:disabled),
.epi-table-toolbar .epi-table-apply-output:focus-visible {
  border-color: #4a969e;
  background: #dff2f3;
  color: #115e67;
}
.epi-table-toolbar .epi-table-apply-output[disabled] {
  background: #e8eeee;
  border-color: #d4dfe0;
  color: #839396;
  box-shadow: none;
}
.epi-table-toolbar .epi-table-consistency-indicator {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 26px;
  padding: 4px 9px;
  border: 1px solid #df9cab;
  border-radius: 999px;
  background: #fff2f5;
  color: #8e4055;
  font-size: 10px;
  font-weight: 650;
  line-height: 1.15;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background-color 180ms ease,
    border-color 180ms ease,
    box-shadow 180ms ease;
}
.epi-table-toolbar .epi-table-consistency-indicator:hover,
.epi-table-toolbar .epi-table-consistency-indicator:focus-visible {
  background: #fde7ec;
  border-color: #cc788c;
  box-shadow: 0 1px 3px rgba(142, 64, 85, 0.12);
  color: #743246;
  outline: none;
}


/* Stage colour used as text. --stage-color-text is emitted alongside
   --stage-color and is already lifted to 4.5:1 on the panel by readableOn. */
html:not([data-theme="light"]) .epi-test-flow-stage-head {
  color: var(--stage-color-text, var(--ps-charcoal));
}
