/* ===========================================================================
   pipeline.css — right pane: pipeline grid (continuous machine column |
   stage header + mechanism column), diagnostic footer, SVG pulse animations.
   =========================================================================== */

/* One grid: column 1 = the four machines stacked edge-to-edge (one continuous
   line joined by pipes); column 2 = each stage's header + mechanism diagram. */
.pipeline-grid {
  display: grid;
  grid-template-columns: minmax(0, 60fr) minmax(0, 40fr); /* = 640 : 420 drawing widths, same scale */
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.machine-cell {
  grid-column: 1;
  display: flex;
  padding: 0 4px;
  background: #ffffff;
  border-right: 1px solid var(--border);
}

/* Fill the whole row height: the exit pipe runs on down to the next stage */
.machine-cell .stage-svg {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.machine-cell.is-bottleneck {
  box-shadow: inset 4px 0 0 #f87171;
}

.mech-cell {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-top: 1px solid var(--border-strong);
  transition: background-color 0.2s ease;
}

.pipeline-grid > .mech-cell:nth-child(2) {
  border-top: none;
}

.mech-cell.is-bottleneck {
  background: #fff7f7;
  box-shadow: inset 4px 0 0 #f87171;
}

.mech-body {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 10px;
}

.mech-body .stage-svg {
  max-width: 560px;
}

.stage-header {
  padding: 12px 18px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.stage-header-left {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 9px;
}

.stage-num {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 13px;
  font-weight: 800;
  flex-shrink: 0;
}

.stage-title {
  margin: 0;
  font-size: 15.5px;
  font-weight: 800;
  color: var(--text-main);
}

.stage-loc {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #334155;
}

.stage-stoich {
  font-size: 12px;
  color: var(--text-soft);
  font-weight: 600;
}

.stage-header-right {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.status-pill {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
}

.status-pill.bottleneck {
  background: #fee2e2;
  color: #b91c1c;
  border-color: #fca5a5;
}

.status-pill.brake {
  background: #fff1f2;
  color: #be123c;
  border-color: #fda4af;
}

.status-pill.strain {
  background: #fef3c7;
  color: #b45309;
  border-color: #fcd34d;
}

.status-pill.clear {
  background: #ecfdf5;
  color: #047857;
  border-color: #a7f3d0;
}

.rpm-pill {
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 8px;
  background: #ffffff;
  border: 1px solid var(--border-strong);
  color: var(--text-main);
}

.stage-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

/* ---- Diagnostic footer ---- */
.diag-footer {
  background: #0f172a;
  color: #f8fafc;
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 14px;
  box-shadow: var(--shadow-card);
}

.diag-badge {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 5px 10px;
  border-radius: 8px;
  flex-shrink: 0;
  margin-top: 2px;
}

.diag-badge.alarm {
  background: rgba(239, 68, 68, 0.22);
  color: #fca5a5;
  border: 1px solid rgba(248, 113, 113, 0.4);
}

.diag-badge.ok {
  background: rgba(16, 185, 129, 0.22);
  color: #6ee7b7;
  border: 1px solid rgba(52, 211, 153, 0.4);
}

.diag-copy {
  flex: 1 1 320px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.diag-line1 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
}

.diag-line2 {
  margin: 0;
  font-size: 12.5px;
  color: #cbd5e1;
}

/* ---- SVG animations & cofactor pulse ---- */
@keyframes alarmPulse {
  0%, 100% { opacity: 0.26; transform: scale(1); }
  50%      { opacity: 0.62; transform: scale(1.06); }
}

.gear-alarm-halo {
  transform-box: fill-box;
  transform-origin: center;
  animation: alarmPulse 0.9s ease-in-out infinite;
}

@keyframes badgePulse {
  0%, 100% { filter: drop-shadow(0 0 0px rgba(220, 38, 38, 0)); }
  50%      { filter: drop-shadow(0 0 5px rgba(220, 38, 38, 0.65)); }
}

.mech-badge-alarm {
  animation: badgePulse 1.1s ease-in-out infinite;
}

/* ---- Very narrow right pane: stack machine above mechanism (pipes then break) ---- */
@container main (max-width: 619px) {
  .pipeline-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .machine-cell,
  .mech-cell {
    grid-column: 1;
  }
  .machine-cell {
    border-right: none;
  }
}

/* Header inside the narrower mechanism column */
.mech-cell .stage-header {
  padding: 10px 12px;
  gap: 6px 10px;
}

.mech-cell .stage-title {
  font-size: 14px;
}

.mech-cell .stage-header-left {
  gap: 5px 7px;
}

.mech-cell .stage-stoich {
  font-size: 10.5px;
}

.mech-cell .stage-header-right {
  gap: 6px;
}

.mech-cell .status-pill,
.mech-cell .rpm-pill {
  font-size: 10px;
  padding: 3px 8px;
}
