/* ==========================================================================
   Workflow section: animated data-flow demonstration (index.html #workflow)
   ========================================================================== */
:root {
  --wf-amber: #fbbf24;
  --wf-amber-bg: rgba(251, 191, 36, 0.14);
  --wf-green-bg: rgba(52, 211, 153, 0.16);
  --wf-red: #f87171;
}

[data-theme="light"] {
  --wf-amber: #b45309;
  --wf-amber-bg: rgba(217, 119, 6, 0.12);
  --wf-green-bg: rgba(5, 150, 105, 0.12);
  --wf-red: #dc2626;
}

.wf-card {
  --wf-progress: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  padding: 40px;
  box-shadow: var(--shadow-card);
}

/* Stage track with a flowing data line */
.wf-track {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  position: relative;
  margin-bottom: 36px;
}

.wf-track::before,
.wf-track::after {
  content: "";
  position: absolute;
  top: 27px;
  left: calc(100% / 14);
  height: 3px;
  border-radius: 3px;
}

.wf-track::before {
  right: calc(100% / 14);
  background: repeating-linear-gradient(90deg, var(--border-strong) 0 10px, transparent 10px 18px);
  background-size: 18px 3px;
  animation: wfFlow 0.9s linear infinite;
}

.wf-track::after {
  width: calc((100% - 100% / 7) * var(--wf-progress));
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-lime));
  box-shadow: 0 0 14px var(--accent-glow);
  transition: width 0.6s ease;
}

@keyframes wfFlow {
  to { background-position: 18px 0; }
}

.wf-node {
  position: relative;
  z-index: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: none;
  border: 0;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  cursor: pointer;
  padding: 0 4px;
  text-align: center;
}

.wf-node-icon {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  font-size: 1.45rem;
  border-radius: 50%;
  background: var(--bg-secondary);
  border: 2px solid var(--border-strong);
  transition: transform 0.35s ease, border-color 0.35s ease, box-shadow 0.35s ease, background 0.35s ease;
}

.wf-node-label {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-primary);
  line-height: 1.2;
}

.wf-node-sub {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.wf-node:hover .wf-node-icon,
.wf-node:focus-visible .wf-node-icon {
  border-color: var(--accent-bright);
}

.wf-node:focus-visible {
  outline: none;
}

.wf-node:focus-visible .wf-node-label {
  text-decoration: underline;
}

.wf-node.done .wf-node-icon {
  border-color: var(--accent-primary);
  background: var(--wf-green-bg);
}

.wf-node.active .wf-node-icon {
  transform: scale(1.14);
  border-color: var(--accent-lime);
  background: var(--bg-card-hover);
  box-shadow: 0 0 0 6px var(--accent-glow), 0 0 26px var(--accent-glow);
  animation: wfPulse 1.8s ease-in-out infinite;
}

.wf-node-human .wf-node-sub {
  color: var(--accent-lime);
}

@keyframes wfPulse {
  50% { box-shadow: 0 0 0 10px transparent, 0 0 30px var(--accent-glow); }
}

/* Stage text + visual */
.wf-stage {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: 36px;
  align-items: center;
}

.wf-title {
  font-size: 1.5rem;
  margin: 10px 0 12px;
  line-height: 1.25;
}

.wf-desc {
  color: var(--text-secondary);
  font-size: 0.98rem;
  margin-bottom: 16px;
}

.wf-who {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-bright);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 6px 12px;
}

.wf-visual {
  min-height: 400px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 22px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 16px;
  overflow: hidden;
}

.wf-mono {
  font-family: var(--font-mono);
}

.wf-table {
  display: grid;
  gap: 8px;
}

.wf-row {
  display: grid;
  grid-template-columns: 1.3fr 1.2fr 1fr 0.5fr;
  gap: 10px;
  align-items: center;
  font-size: 0.82rem;
  color: var(--text-primary);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
}

.wf-row > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wf-head {
  background: none;
  border: 0;
  padding-top: 0;
  padding-bottom: 0;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.wf-raw .wf-row:not(.wf-head) {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--text-secondary);
  border-style: dashed;
}

.wf-map .wf-row {
  grid-template-columns: 1.15fr auto 1.25fr 0.9fr auto;
}

.wf-map .wf-row.wf-reviewed {
  grid-template-columns: 1.15fr auto 1.5fr auto;
}

.wf-row small {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Mapping rows wrap instead of cutting names short */
.wf-map .wf-row > span {
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.3;
}

.wf-arrow {
  color: var(--accent-bright);
  font-weight: 700;
}

.wf-code b {
  color: var(--accent-bright);
}

.wf-code s {
  color: var(--wf-red);
  font-family: var(--font-mono);
  margin-right: 4px;
}

.wf-code .wf-fix {
  color: var(--accent-lime);
}

.wf-flagged {
  border-color: var(--wf-amber);
  background: var(--wf-amber-bg);
}

.wf-conf-bar {
  display: block;
  height: 6px;
  border-radius: 6px;
  background: var(--border-subtle);
  overflow: hidden;
  margin-bottom: 4px;
}

.wf-conf-bar i,
.wf-bar i {
  display: block;
  height: 100%;
  width: var(--w);
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-lime));
}

.wf-flagged .wf-conf-bar i {
  background: var(--wf-amber);
}

.wf-flagged .wf-conf small {
  color: var(--wf-amber);
}

.wf-status {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 4px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.wf-status-pending {
  color: var(--wf-amber);
  background: var(--wf-amber-bg);
}

.wf-status-approved {
  color: var(--accent-bright);
  background: var(--wf-green-bg);
}

/* PENDING flips to APPROVED during the review stage */
.wf-flip {
  display: grid;
  justify-items: end;
}

.wf-flip > span {
  grid-area: 1 / 1;
}

.wf-flip .wf-status-approved {
  opacity: 0;
  transform: scale(0.6);
}

.wf-foot,
.wf-stamp {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.wf-stamp {
  color: var(--text-secondary);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.wf-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.wf-chip {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--accent-bright);
  background: var(--wf-green-bg);
  border-radius: 999px;
  padding: 6px 11px;
}

/* Quality gate */
.wf-gate {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 24px;
  align-items: center;
}

.wf-ring {
  position: relative;
  width: 130px;
  height: 130px;
}

.wf-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.wf-ring circle {
  fill: none;
  stroke-width: 9;
}

.wf-ring-bg {
  stroke: var(--border-subtle);
}

.wf-ring-fg {
  stroke: var(--accent-bright);
  stroke-linecap: round;
  stroke-dasharray: 327;
  stroke-dashoffset: 0;
}

.wf-lock,
.wf-unlock {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 2.2rem;
}

.wf-lock {
  opacity: 0;
}

.wf-gate-list {
  display: grid;
  gap: 8px;
}

.wf-check {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.86rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 8px;
}

.wf-check b {
  color: var(--accent-bright);
}

.wf-gate-ok {
  font-weight: 700;
  color: var(--accent-bright);
  margin-top: 4px;
}

/* Calculation */
.wf-formula {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.wf-term {
  flex: 1 1 110px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: grid;
  gap: 2px;
}

.wf-term small,
.wf-total small {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.wf-term b {
  font-size: 1.15rem;
  color: var(--text-primary);
}

.wf-term em {
  font-style: normal;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.wf-op {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent-bright);
}

.wf-result {
  border-color: var(--accent-lime);
  box-shadow: 0 0 22px var(--accent-glow);
}

.wf-result b {
  color: var(--accent-lime);
}

/* Footprint */
.wf-total {
  display: grid;
  gap: 2px;
}

.wf-total b {
  font-size: 2rem;
  color: var(--accent-lime);
  line-height: 1.1;
}

.wf-bars {
  display: grid;
  gap: 10px;
}

.wf-bar-row {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  font-size: 0.82rem;
}

.wf-bar-label {
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wf-bar {
  display: block;
  height: 12px;
  border-radius: 12px;
  background: var(--border-subtle);
  overflow: hidden;
}

/* Controls */
.wf-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 24px;
}

.wf-btn {
  font-size: 1rem;
  font-weight: 700;
}

.wf-progress {
  flex: 1;
  height: 4px;
  border-radius: 4px;
  background: var(--border-subtle);
  overflow: hidden;
}

.wf-progress span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent-bright);
}

.wf-note {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Entrance animations (replayed on every stage change) */
.wf-animate .wf-in {
  opacity: 0;
  animation: wfIn 0.5s ease forwards;
  animation-delay: calc(var(--i, 0) * 140ms);
}

.wf-animate .wf-pop {
  opacity: 0;
  animation: wfPop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  animation-delay: calc(var(--i, 0) * 140ms + 150ms);
}

.wf-animate .wf-conf-bar i,
.wf-animate .wf-bar i {
  width: 0;
  animation: wfGrow 0.9s ease forwards;
  animation-delay: calc(var(--i, 0) * 140ms + 300ms);
}

.wf-animate .wf-flip .wf-status-pending {
  animation: wfOut 0.3s ease forwards;
  animation-delay: calc(var(--i, 0) * 140ms + 200ms);
}

.wf-animate .wf-flip .wf-status-approved {
  animation: wfPop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  animation-delay: calc(var(--i, 0) * 140ms + 380ms);
}

.wf-animate .wf-ring-fg {
  stroke-dashoffset: 327;
  animation: wfRing 1.1s ease forwards 0.2s;
}

.wf-animate .wf-lock {
  opacity: 1;
  animation: wfOut 0.3s ease forwards 1.3s;
}

.wf-animate .wf-unlock {
  opacity: 0;
  animation: wfPop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards 1.45s;
}

@keyframes wfIn {
  from { opacity: 0; transform: translateX(-14px); }
  to { opacity: 1; transform: none; }
}

@keyframes wfPop {
  from { opacity: 0; transform: scale(0.6); }
  to { opacity: 1; transform: none; }
}

@keyframes wfOut {
  to { opacity: 0; transform: scale(0.6); }
}

@keyframes wfGrow {
  from { width: 0; }
  to { width: var(--w); }
}

@keyframes wfRing {
  to { stroke-dashoffset: 0; }
}

@media (max-width: 1180px) {
  .wf-stage {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .wf-stage-text {
    min-height: 190px;
  }

  .wf-visual {
    min-height: 380px;
  }
}

@media (max-width: 768px) {
  .wf-card {
    padding: 24px 16px;
  }

  .wf-track {
    margin-bottom: 26px;
  }

  .wf-track::before,
  .wf-track::after {
    top: 19px;
  }

  .wf-node {
    padding: 0 1px;
  }

  .wf-node-icon {
    width: 40px;
    height: 40px;
    font-size: 1.05rem;
  }

  .wf-node-sub {
    display: none;
  }

  .wf-node-label {
    font-size: 0.62rem;
  }

  .wf-visual {
    min-height: 340px;
    padding: 14px;
  }

  .wf-row > span {
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.3;
  }

  .wf-title {
    font-size: 1.25rem;
  }

  /* Raw/clean tables: drop the account column on small screens */
  .wf-table:not(.wf-map) .wf-row {
    grid-template-columns: 1.3fr 1fr 0.5fr;
    font-size: 0.74rem;
    padding: 8px 10px;
  }

  .wf-table:not(.wf-map) .wf-row > span:nth-child(2) {
    display: none;
  }

  .wf-map .wf-row {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto;
    font-size: 0.74rem;
    padding: 8px 10px;
  }

  .wf-map .wf-conf {
    display: none;
  }

  .wf-map .wf-row.wf-reviewed {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1.2fr) auto;
  }

  .wf-gate {
    grid-template-columns: 90px 1fr;
    gap: 16px;
  }

  .wf-ring {
    width: 90px;
    height: 90px;
  }

  .wf-bar-row {
    grid-template-columns: minmax(0, 1fr) auto;
    row-gap: 6px;
  }

  .wf-bar-row .wf-bar {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .wf-note {
    display: none;
  }
}

/* Phones: tall enough for the tallest stage, so auto-advance never makes the page jump */
@media (max-width: 560px) {
  .wf-visual {
    min-height: 520px;
  }

  .wf-stage-text {
    min-height: 290px;
  }
}

@media (max-width: 480px) {
  .wf-node-label {
    display: none;
  }

  .wf-node-icon {
    width: 36px;
    height: 36px;
    font-size: 0.95rem;
  }

  .wf-track::before,
  .wf-track::after {
    top: 17px;
  }

  .wf-node.active .wf-node-icon {
    transform: scale(1.08);
    box-shadow: 0 0 0 4px var(--accent-glow);
  }
}

@media (prefers-reduced-motion: reduce) {
  .wf-track::before,
  .wf-node.active .wf-node-icon {
    animation: none;
  }

  .wf-animate .wf-in,
  .wf-animate .wf-pop,
  .wf-animate .wf-unlock {
    animation: none;
    opacity: 1;
  }

  .wf-animate .wf-conf-bar i,
  .wf-animate .wf-bar i {
    animation: none;
    width: var(--w);
  }

  .wf-animate .wf-flip .wf-status-pending,
  .wf-animate .wf-lock {
    animation: none;
    opacity: 0;
  }

  .wf-animate .wf-flip .wf-status-approved {
    animation: none;
    opacity: 1;
    transform: none;
  }

  .wf-animate .wf-ring-fg {
    animation: none;
    stroke-dashoffset: 0;
  }
}
