/* ==========================================================================
   LIVE DIAGRAMS — shared "stage" component for the architecture tiers,
   the end-to-end pipeline and the integration hub.
   Data packets are full-width gradient strips or short bars moved with
   translate3d, so every flow animation stays on the compositor.
   ========================================================================== */

/* --------------------------------------------------------------------------
   STAGE SHELL
   -------------------------------------------------------------------------- */
.stage {
  position: relative;
  margin-top: 16px;
  border-radius: var(--radius-xl);
  background: var(--surface-1);
  border: 1px solid var(--line-1);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.bento + .stage { margin-top: 16px; }

.stage-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  padding: clamp(20px, 2vw, 32px);
  border-bottom: 1px solid var(--line-1);
}

.stage-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  color: var(--text-3);
  margin-bottom: 10px;
}

.stage-title { font-size: clamp(1.2rem, 1.6vw, 1.55rem); font-weight: 600; letter-spacing: -0.02em; margin-bottom: 6px; }
.stage-desc { font-size: 0.88rem; color: var(--text-3); line-height: 1.55; max-width: 620px; }

.stage-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-width: 0; max-width: 100%; }

.stage-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  color: var(--text-2);
  transition: border-color var(--dur-1) var(--ease-hover), color var(--dur-1) var(--ease-hover), transform var(--dur-2) var(--ease-out);
}

.stage-toggle:hover { border-color: var(--line-3); color: var(--text-1); }
.stage-toggle:active { transform: scale(0.96); }

.stage-toggle-dot {
  position: relative;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
}

.stage-toggle-dot::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--ok);
  animation: pingRing 2s var(--ease-out) infinite;
}

.stage.is-paused .stage-toggle-dot { background: var(--text-4); }
.stage.is-paused .stage-toggle-dot::after { display: none; }

/* Pause every flow inside a stage in one switch */
.stage.is-paused *,
.stage.is-offscreen * { animation-play-state: paused !important; }

/* Segmented quick-select (sliding pill positioned by micro-interactions.js) */
.seg {
  position: relative;
  display: flex;
  align-items: center;
  padding: 3px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line-1);
  overflow-x: auto;
  scrollbar-width: none;
  max-width: 100%;
}

.seg::-webkit-scrollbar { display: none; }

.seg-btn {
  position: relative;
  z-index: 1;
  height: 28px;
  padding: 0 12px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--text-3);
  white-space: nowrap;
  transition: color var(--dur-1) var(--ease-hover);
}

.seg-btn:hover, .seg-btn.active { color: var(--text-1); }

.stage-body { padding: clamp(20px, 2vw, 32px); }

.stage-body-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 0.42fr);
  gap: clamp(16px, 2vw, 32px);
  align-items: start;
}

.stage-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  flex-wrap: wrap;
  padding: 14px clamp(20px, 2vw, 32px);
  border-top: 1px solid var(--line-1);
  background: rgba(0, 0, 0, 0.2);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  color: var(--text-4);
}

.stage-status-left { display: inline-flex; align-items: center; gap: 8px; color: var(--text-2); }
.stage-status-metrics { display: flex; gap: 18px; flex-wrap: wrap; }
.stage-status strong { color: var(--text-1); font-weight: 500; font-variant-numeric: tabular-nums; }

/* Shared "scan" band that sweeps the active item */
.tier-scan {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(90deg, transparent 0%, rgba(255, 51, 102, 0.12) 50%, transparent 100%);
  transform: translate3d(-100%, 0, 0);
  opacity: 0;
}

.is-active > .tier-scan { opacity: 1; animation: scanSweep 1.8s var(--ease-in-out) infinite; }

@keyframes scanSweep { to { transform: translate3d(100%, 0, 0); } }

/* Packets */
.packet {
  position: absolute;
  left: 0;
  top: 0;
  width: 2px;
  height: 14px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.55);
  animation: railDown 1.8s linear infinite;
}

.packet.is-up { animation-name: railUp; }
.packet.is-late { animation-delay: -0.9s; }

.packet-h {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, transparent 38%, rgba(255, 255, 255, 0.5) 49%, rgba(255, 255, 255, 0.9) 50%, transparent 52%, transparent 100%);
  transform: translate3d(-60%, 0, 0);
  animation: stripX 2.2s linear infinite;
}

.packet-h.is-late { animation-delay: -1.1s; }
.packet-h.is-rev { animation-direction: reverse; animation-duration: 3.4s; opacity: 0.6; }

@keyframes stripX { to { transform: translate3d(60%, 0, 0); } }
@keyframes stripY { from { transform: translate3d(0, -60%, 0); } to { transform: translate3d(0, 60%, 0); } }

/* --------------------------------------------------------------------------
   ARCHITECTURE — stacked tiers joined by bidirectional conduits
   -------------------------------------------------------------------------- */
.tier-stack { display: flex; flex-direction: column; }

.tier {
  position: relative;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 16px 20px;
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  border: 1px solid var(--line-1);
  text-align: left;
  overflow: hidden;
  transition: border-color var(--dur-2) var(--ease-hover), background-color var(--dur-2) var(--ease-hover), transform var(--dur-2) var(--ease-out);
}

.tier:hover { border-color: var(--line-3); }
.tier:active { transform: scale(0.995); }

.tier.is-active {
  border-color: var(--accent-line);
  background: linear-gradient(90deg, rgba(255, 51, 102, 0.08), transparent 60%), var(--surface-2);
}

.tier-badge {
  position: relative;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: 1px solid var(--line-2);
  background: rgba(0, 0, 0, 0.3);
  font-family: var(--font-mono);
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-2);
  transition: color var(--dur-1) var(--ease-hover), border-color var(--dur-2) var(--ease-hover);
}

.tier.is-active .tier-badge { color: var(--accent); border-color: rgba(255, 51, 102, 0.45); }

.tier-badge-ring {
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  border: 1px solid var(--accent);
  opacity: 0;
}

.tier.is-active .tier-badge-ring { animation: badgeRing 1.8s var(--ease-out) infinite; }

@keyframes badgeRing {
  from { transform: scale(1); opacity: 0.7; }
  to { transform: scale(1.45); opacity: 0; }
}

.tier-info { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tier-name-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; }
.tier-name { font-size: 0.96rem; font-weight: 600; letter-spacing: -0.01em; color: var(--text-1); }

.tier-pill {
  padding: 2px 7px;
  border-radius: 5px;
  border: 1px solid var(--line-2);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  color: var(--text-3);
}

.tier.is-active .tier-pill { color: var(--accent); border-color: rgba(255, 51, 102, 0.35); }

.tier-summary { font-size: 0.84rem; color: var(--text-3); line-height: 1.5; }

.tier-live { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; font-family: var(--font-mono); }
.tier-live-label { display: inline-flex; align-items: center; gap: 8px; font-size: 0.68rem; letter-spacing: 0.08em; color: var(--text-4); }
.tier-live-val { font-size: 0.76rem; color: var(--text-1); white-space: nowrap; font-variant-numeric: tabular-nums; }

.eq { display: inline-flex; align-items: flex-end; gap: 2px; height: 10px; }

.eq i {
  width: 2px;
  height: 100%;
  border-radius: 1px;
  background: var(--text-4);
  transform-origin: 50% 100%;
  animation: equalizerFlutter 0.9s ease-in-out infinite alternate;
}

.eq i:nth-child(2) { animation-delay: -0.3s; }
.eq i:nth-child(3) { animation-delay: -0.6s; }
.eq i:nth-child(4) { animation-delay: -0.15s; }
.eq i:nth-child(5) { animation-delay: -0.45s; }
.tier.is-active .eq i { background: var(--accent); }

.conduit {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: 52px;
}

.conduit-rail {
  position: relative;
  justify-self: center;
  width: 2px;
  height: 100%;
  background: var(--line-2);
  overflow: hidden;
}

.conduit-chip {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line-1);
  background: var(--surface-1);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  color: var(--text-4);
  white-space: nowrap;
  transition: color var(--dur-1) var(--ease-hover), border-color var(--dur-2) var(--ease-hover);
}

.conduit.is-active .conduit-rail { background: rgba(255, 51, 102, 0.25); }
.conduit.is-active .packet { background: var(--accent); box-shadow: 0 0 10px var(--accent); animation-duration: 0.9s; }
.conduit.is-active .conduit-chip { color: var(--text-1); border-color: rgba(255, 51, 102, 0.35); }

/* Inspector (shared) */
.inspector {
  position: sticky;
  top: calc(var(--header-height) + 16px);
  padding: clamp(18px, 1.6vw, 26px);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  min-height: 220px;
}

.inspector-inner { transition: opacity var(--dur-2) var(--ease-hover), transform var(--dur-3) var(--ease-out); }
.inspector-inner.is-swapping { opacity: 0; transform: translate3d(0, 6px, 0); transition-duration: 120ms; }

.inspector-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 10px;
}

.inspector-title { font-size: 1.08rem; font-weight: 600; letter-spacing: -0.015em; line-height: 1.35; margin-bottom: 10px; }
.inspector-summary { font-size: 0.86rem; color: var(--text-3); line-height: 1.6; margin-bottom: 18px; }

.inspector-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  border-radius: var(--radius-md);
  background: var(--line-1);
  border: 1px solid var(--line-1);
  overflow: hidden;
}

.inspector-stat { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; background: var(--surface-2); }
.inspector-stat span { font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.06em; color: var(--text-4); overflow-wrap: break-word; }
.inspector-stat strong { font-size: 0.84rem; font-weight: 500; color: var(--text-1); overflow-wrap: break-word; }

.inspector-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.inspector-chips span { padding: 3px 8px; border-radius: 6px; border: 1px solid var(--line-2); font-family: var(--font-mono); font-size: 0.68rem; color: var(--text-2); }

/* Wide inspector: copy beside stats (pipeline + hub) */
.inspector-wide { position: relative; top: auto; margin-top: 20px; min-height: 0; }
.inspector-wide .inspector-inner { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px 32px; align-items: start; }
.inspector-wide .inspector-summary { margin-bottom: 0; }

/* --------------------------------------------------------------------------
   PIPELINE — four nodes joined by horizontal conduits
   -------------------------------------------------------------------------- */
.flow {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px minmax(0, 1fr) 40px minmax(0, 1fr) 40px minmax(0, 1fr);
  align-items: stretch;
}

.flow-node {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 20px;
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  border: 1px solid var(--line-1);
  text-align: left;
  overflow: hidden;
  transition: border-color var(--dur-2) var(--ease-hover), background-color var(--dur-2) var(--ease-hover), transform var(--dur-2) var(--ease-out);
}

.flow-node:hover { border-color: var(--line-3); }
.flow-node:active { transform: scale(0.99); }

.flow-node.is-active {
  border-color: var(--accent-line);
  background: linear-gradient(180deg, rgba(255, 51, 102, 0.08), transparent 55%), var(--surface-2);
}

.flow-node-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }

.flow-num {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line-2);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-2);
  transition: color var(--dur-1) var(--ease-hover), border-color var(--dur-2) var(--ease-hover);
}

.flow-node.is-active .flow-num { color: var(--accent); border-color: rgba(255, 51, 102, 0.45); }

.flow-tag { display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.08em; color: var(--text-4); }
.flow-tag-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--text-4); }
.flow-node.is-active .flow-tag-dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); }

.flow-title { font-size: 1.02rem; font-weight: 600; letter-spacing: -0.015em; color: var(--text-1); }
.flow-sub { font-family: var(--font-mono); font-size: 0.68rem; color: var(--text-4); margin-bottom: 8px; }

.flow-list { display: flex; flex-direction: column; gap: 7px; margin-bottom: 14px; flex: 1; }

.flow-list span {
  position: relative;
  padding-left: 14px;
  font-size: 0.82rem;
  color: var(--text-3);
}

.flow-list span::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.6em;
  width: 5px;
  height: 5px;
  border-radius: 1px;
  background: var(--line-3);
}

.flow-node.is-active .flow-list span::before { background: var(--accent); }

.flow-foot {
  padding-top: 12px;
  border-top: 1px solid var(--line-1);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  color: var(--text-2);
}

.flow-link { align-self: center; height: 2px; position: relative; }

.flow-link-track {
  position: absolute;
  inset: 0;
  background: var(--line-2);
  overflow: hidden;
}

.flow-link .packet-h { opacity: 0.4; }
.flow-link.is-active .flow-link-track { background: rgba(255, 51, 102, 0.3); }

.flow-link.is-active .packet-h {
  opacity: 1;
  background: linear-gradient(90deg, transparent 0%, transparent 36%, rgba(255, 51, 102, 0.9) 48%, #FFFFFF 50%, transparent 53%, transparent 100%);
  animation-duration: 1.1s;
}

/* --------------------------------------------------------------------------
   INTEGRATION HUB — shared bus feeding four pillars
   -------------------------------------------------------------------------- */
.hub-bus { position: relative; display: grid; place-items: center; height: 36px; }

.hub-bus-line {
  position: absolute;
  left: 12.5%;
  right: 12.5%;
  top: 50%;
  height: 2px;
  margin-top: -1px;
  background: rgba(255, 51, 102, 0.22);
  overflow: hidden;
}

.hub-bus-line .packet-h {
  background: linear-gradient(90deg, transparent 0%, transparent 40%, rgba(255, 51, 102, 0.9) 49%, #FFFFFF 50%, transparent 52%, transparent 100%);
}

.hub-bus-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 51, 102, 0.35);
  background: var(--surface-1);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  color: var(--text-1);
  box-shadow: 0 0 24px -8px var(--accent-glow);
}

.hub-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

/* Stubs from the bus down to each pillar, laid out on the same 4 columns */
.hub-stubs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  height: 30px;
}

.hub-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 22px;
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  border: 1px solid var(--line-1);
  text-align: left;
  overflow: hidden;
  transition: border-color var(--dur-2) var(--ease-hover), background-color var(--dur-2) var(--ease-hover), transform var(--dur-2) var(--ease-out);
}

.hub-card:hover { border-color: var(--line-3); }
.hub-card:active { transform: scale(0.99); }

.hub-card.is-active {
  border-color: var(--accent-line);
  background: linear-gradient(180deg, rgba(255, 51, 102, 0.08), transparent 55%), var(--surface-2);
}

.hub-stub {
  position: relative;
  justify-self: center;
  width: 2px;
  height: 100%;
  background: var(--line-2);
  overflow: hidden;
}

.hub-stub .packet { animation-name: railUp; }
.hub-stub.is-active { background: rgba(255, 51, 102, 0.3); }
.hub-stub.is-active .packet { background: var(--accent); box-shadow: 0 0 8px var(--accent); animation-duration: 0.9s; }

.hub-card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.hub-card.is-active .card-icon-box { color: var(--accent); border-color: rgba(255, 51, 102, 0.35); }

.hub-title { font-size: 1.02rem; font-weight: 600; letter-spacing: -0.015em; color: var(--text-1); }
.hub-desc { font-size: 0.84rem; color: var(--text-3); line-height: 1.55; flex: 1; }
.hub-card .eco-partner-pills { margin-top: 4px; }

.hub-metric {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding-top: 12px;
  margin-top: 4px;
  border-top: 1px solid var(--line-1);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-4);
}

.hub-metric strong { color: var(--text-1); font-weight: 500; }
.hub-card.is-active .hub-metric strong { color: var(--accent); }

/* Partner pills (shared with hub cards) */
.eco-partner-pills { display: flex; flex-wrap: wrap; gap: 6px; }

.eco-partner-pill {
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid var(--line-1);
  font-size: 0.68rem;
  font-family: var(--font-mono);
  color: var(--text-3);
  transition: color var(--dur-1) var(--ease-hover), border-color var(--dur-1) var(--ease-hover);
}

.hub-card:hover .eco-partner-pill, .hub-card.is-active .eco-partner-pill { color: var(--text-2); border-color: var(--line-2); }

/* --------------------------------------------------------------------------
   RESPONSIVE
   -------------------------------------------------------------------------- */
@media (max-width: 1280px) {
  .stage-body-split { grid-template-columns: 1fr; }
  .inspector { position: relative; top: auto; min-height: 0; }
  .flow { grid-template-columns: minmax(0, 1fr) 40px minmax(0, 1fr); row-gap: 16px; }
  .flow-link[data-conduit="2"] { display: none; }
}

@media (max-width: 1024px) {
  .hub-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 16px; }
  .hub-stubs, .hub-bus-line { display: none; }
  .hub-bus { height: auto; }
  .inspector-wide .inspector-inner { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .stage-head { align-items: flex-start; }
  .stage-controls { width: 100%; }
  .seg { flex: 1 1 auto; min-width: 0; }
  .tier { grid-template-columns: 44px minmax(0, 1fr); gap: 14px; padding: 14px; }
  .tier-badge { width: 42px; height: 42px; }
  .tier-live { grid-column: 1 / -1; flex-direction: row; justify-content: space-between; align-items: center; gap: 12px; }
  .tier-live-val { white-space: normal; text-align: right; min-width: 0; }
  /* Protocol chips are secondary detail; on phones the rails alone carry the flow */
  .conduit { height: 28px; }
  .conduit-chip { display: none; }

  /* Pipeline becomes a vertical chain */
  .flow { grid-template-columns: 1fr; row-gap: 0; }
  .flow-link, .flow-link[data-conduit="2"] { display: block; justify-self: center; width: 2px; height: 32px; }
  .flow-link .packet-h,
  .flow-link.is-active .packet-h {
    background: linear-gradient(180deg, transparent 0%, transparent 38%, var(--accent) 49%, #FFFFFF 50%, transparent 53%, transparent 100%);
    animation-name: stripY;
  }
  .hub-grid { grid-template-columns: 1fr; }
  .stage-status { flex-direction: column; align-items: flex-start; }
}

/* Small phones: inspector stats stack so long labels keep whole words */
@media (max-width: 420px) {
  .inspector-stats { grid-template-columns: 1fr; }
}

/* Touch screens: segmented controls reach a comfortable tap height */
@media (pointer: coarse), (max-width: 768px) {
  .seg-btn, .stage-toggle { height: 36px; }
}

@media (prefers-reduced-motion: reduce) {
  .packet, .packet-h, .tier-scan { display: none; }
}
