/* ==========================================================================
   Leitstand (.team) — fünf Agenten, ein Server, ein Zustand.

   Links die Agenten, in der Mitte die Leitungen, rechts der Server: oben, was
   er gerade weiß (fällt beim Neustart weg), darunter state.db (bleibt).
   Jede Karte zeichnet ihren Lauf als Spur auf: arbeiten, warten, abgestürzt.
   ========================================================================== */

/* Die Bühne der Projektseite gibt ein Seitenverhältnis vor; der Leitstand
   bestimmt seine Höhe selbst. */
.case-stage .project-visual:has(> .team) { grid-template-columns: minmax(0, 1fr); aspect-ratio: auto; place-items: stretch; }

.team {
  --t-gap: 1.1rem;
  width: 100%;
  min-width: 0;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: none;
}
/* Das Punktraster der Bühne bleibt hinter den Leitungen, nicht hinter Text */
.team .demo-head,
.team-foot { background: var(--c-dark); }
.team .demo-title { font-size: 1.15rem; line-height: 1.3; }
.team-run { display: flex; align-items: center; gap: 0.85rem; }
.team-clock { font-family: var(--font-mono); font-size: 0.85rem; font-variant-numeric: tabular-nums; color: var(--c-dark-ink-2); }
.team-label { font-family: var(--font-mono); font-size: 0.72rem; color: var(--d-ink-3); }

.team-board {
  display: grid;
  grid-template-columns: 13.5rem minmax(5rem, 1fr) minmax(0, 38rem);
  padding: var(--t-gap);
}

/* ---- Agenten ------------------------------------------------------------- */
.team-agents { display: grid; grid-auto-rows: 1fr; list-style: none; margin: 0; padding: 0; z-index: 1; }
.team-agents li { display: grid; padding-block: 0.3rem; }
.team-agent {
  --_s: var(--d-ink-3);
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-content: center;
  gap: 0.1rem 0.65rem;
  width: 100%;
  min-height: 4.4rem;
  padding: 0.6rem 0.75rem 0.85rem;
  border: 1px solid var(--d-line);
  border-radius: var(--radius-s);
  background: var(--d-panel);
  color: var(--c-dark-ink);
  text-align: left;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.25s var(--ease), background 0.25s var(--ease);
}
.team-agent:disabled { cursor: default; }
.team-agent .who { --_c: var(--_s); grid-row: span 2; align-self: center; }
.team-agent b { font: 560 0.9rem/1.3 var(--font-sans); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.team-phase { font: 400 0.7rem/1.35 var(--font-mono); color: var(--c-dark-ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.team-agent[data-state="work"] { --_s: var(--d-accent); border-color: var(--d-line-2); }
.team-agent[data-state="work"] .who { background: var(--_s); color: var(--c-dark); }
.team-agent[data-state="queue"],
.team-agent[data-state="retry"] { --_s: var(--d-wait); }
.team-agent[data-state="queue"] .team-phase,
.team-agent[data-state="retry"] .team-phase { color: var(--d-wait); }
.team-agent[data-state="down"],
.team-agent[data-state="join"] { --_s: var(--d-no); border: 1px dashed var(--d-no); background: transparent; }
.team-agent[data-state="down"] .team-phase,
.team-agent[data-state="join"] .team-phase { color: var(--d-no); }
.team-agent[data-state="down"] b { color: var(--d-ink-3); }
.team-agent[data-state="done"] { --_s: var(--d-ok); }
.team-agent[data-state="done"] .who { background: var(--_s); color: var(--c-dark); }
@media (hover: hover) {
  .team-agent:not(:disabled):hover { border-color: var(--d-no); background: color-mix(in srgb, var(--d-no) 8%, var(--c-dark)); }
}

/* Spur: was der Agent wann getan hat */
.team-trace { position: absolute; inset: auto 0 0; display: flex; height: 5px; background: color-mix(in srgb, var(--c-dark-ink) 5%, transparent); }
.team-trace i { flex: none; height: 100%; }
.team-trace .is-work { background: var(--d-accent); }
.team-trace .is-wait { background: linear-gradient(var(--d-line-2), var(--d-line-2)) center / 100% 1px no-repeat; }
.team-trace .is-down { background: repeating-linear-gradient(135deg, var(--d-no) 0 2px, transparent 2px 5px); }

/* ---- Leitungen und Pakete ------------------------------------------------ */
.team-links { position: relative; }
.team-links svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.team-links path {
  fill: none;
  stroke: color-mix(in srgb, var(--c-dark-ink) 24%, transparent);
  stroke-width: 1.25;
  vector-effect: non-scaling-stroke;
  transition: stroke 0.35s var(--ease);
}
.team-links path.is-live { stroke: var(--d-signal); transition-duration: 0.05s; }
.team-links path.is-cut { stroke: var(--d-line); stroke-dasharray: 2 6; }

/* Aufruf zum Server: mit Namen. Antwort oder Wecken: kleines Quadrat. */
.team-packet {
  --_k: var(--d-accent);
  position: absolute;
  top: 0; left: 0;
  padding: 0.35rem 0.6rem;
  border-radius: 2px;
  background: var(--_k);
  color: var(--c-dark);
  font: 600 0.82rem/1 var(--font-mono);
  white-space: nowrap;
  will-change: transform;
}
.team-packet:empty { width: 9px; height: 9px; padding: 0; outline: 2px solid var(--c-dark); }
.team-packet[data-kind="reserve"],
.team-packet[data-kind="release"],
.team-packet[data-kind="join"] { --_k: var(--d-signal); }
.team-packet[data-kind="ack"],
.team-packet[data-kind="vote"],
.team-packet[data-kind="pass"] { --_k: var(--d-ok); }

/* ---- Server -------------------------------------------------------------- */
.team-server { display: grid; grid-template-rows: 1fr auto; min-width: 0; padding-block: 0.3rem; z-index: 1; }
.team-live {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.12fr);
  border: 1px solid var(--d-signal);
  border-bottom: 0;
  border-radius: var(--radius-s) var(--radius-s) 0 0;
  background: color-mix(in srgb, var(--c-accent) 14%, var(--c-dark));
  transition: border-color 0.3s var(--ease), background 0.3s var(--ease);
}
.team-state { display: grid; align-content: start; gap: 0.4rem; padding: 0.9rem 1rem; }
.team-state .team-label + * { margin-bottom: 0.55rem; }
.team-name { margin-bottom: 0.35rem; font: 600 1rem/1.3 var(--font-mono); color: #fff; }
.team-files { list-style: none; margin: 0; padding: 0; }
.team-files li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 2rem;
  border-top: 1px solid var(--d-line);
}
.team-files li:last-child { border-bottom: 1px solid var(--d-line); }
.team-files code { font-family: var(--font-mono); font-size: 0.78rem; color: var(--c-dark-ink); }
.team-hold,
.team-marks { display: flex; gap: 0.3rem; }
.team-hold .who { --_c: var(--d-signal); animation: team-pop 0.3s var(--ease); }
.team-hold .who--queue { --_c: var(--d-wait); border-style: dashed; color: var(--d-wait); }
.team-marks .who--on { --_c: var(--d-ok); }
@keyframes team-pop { from { transform: scale(0.4); opacity: 0; } }

/* Protokoll: neue Zeilen kommen unten an, das Älteste verschwindet oben */
.team-log {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 0.5rem;
  min-height: 0;
  padding: 0.95rem 0 0 1rem;
  border-left: 1px solid var(--d-line);
}
.team-feed {
  height: 0;
  min-height: 100%;
  margin: 0;
  padding: 0 0.75rem 0.6rem 0;
  list-style: none;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--d-line-2) transparent;
  counter-reset: seq;
  font: 400 0.74rem/1.4 var(--font-sans);
  color: var(--c-dark-ink-2);
}
.js .team[data-state="run"] .team-feed,
.js .team[data-state="outage"] .team-feed { overflow: hidden; }
.team-feed li {
  display: flex;
  gap: 0.45em;
  align-items: baseline;
  padding-block: 0.16rem;
  white-space: nowrap;
}
.team-feed li:not(.is-note) { counter-increment: seq; }
.team-feed li:not(.is-note)::before {
  content: counter(seq);
  flex: none;
  width: 1.5em;
  font-family: var(--font-mono);
  color: var(--d-ink-3);
  text-align: right;
}
.team-feed b { font-family: var(--font-mono); font-weight: 600; color: var(--c-dark-ink); }
.team-feed code { font-family: var(--font-mono); color: var(--d-accent); }
.team-feed [data-do="reserve"] code,
.team-feed [data-do="release"] code { color: var(--d-signal); }
.team-feed [data-do="ack"] code,
.team-feed [data-do="vote"] code,
.team-feed [data-do="pass"] code { color: var(--d-ok); }
.team-feed .is-note { display: block; margin-block: 0.2rem; padding-left: 0.5rem; border-left: 3px solid var(--d-no); color: var(--d-no); }
.js .team-feed li { animation: team-row 0.6s var(--ease); }
@keyframes team-row { from { opacity: 0; transform: translateY(8px); } }

/* state.db: das Band wächst mit jedem Ereignis und übersteht den Neustart */
.team-db {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.9rem;
  padding: 0.7rem 1rem;
  border: 1px solid var(--d-signal);
  border-radius: 0 0 var(--radius-s) var(--radius-s);
  background: color-mix(in srgb, var(--c-signal) 12%, var(--c-dark));
  font: 400 0.72rem/1.3 var(--font-mono);
  color: var(--c-dark-ink-2);
}
.team-db b { font-weight: 600; font-size: 0.8rem; color: #fff; }
.team-db > span:last-child { white-space: nowrap; font-variant-numeric: tabular-nums; }
.team-tape {
  --n: 23;
  height: 14px;
  background: repeating-linear-gradient(90deg, var(--d-signal) 0 4px, transparent 4px 10px) left / calc(var(--n) * 10px) 100% no-repeat;
}

/* Neustart: oben dunkel und schraffiert, state.db bleibt, wie sie ist */
.team[data-state="outage"] .team-live {
  border-color: var(--d-line-2);
  border-style: dashed;
  background: repeating-linear-gradient(135deg, var(--d-line) 0 1px, transparent 1px 9px), var(--c-dark);
}
.team-state > *,
.team-log > * { transition: opacity 0.45s var(--ease); }
.team[data-state="outage"] .team-state > *,
.team[data-state="outage"] .team-log > * { opacity: 0.14; transition-duration: 0.15s; }
/* … und kommt Zeile für Zeile zurück */
.team-state > :nth-child(2),
.team-state > :nth-child(3) { transition-delay: 0.15s; }
.team-state > :nth-child(4),
.team-state > :nth-child(5) { transition-delay: 0.35s; }
.team-state > :nth-child(6),
.team-state > :nth-child(7) { transition-delay: 0.55s; }
.team[data-state="outage"] .team-state > * { transition-delay: 0s; }

/* Hier kommt etwas an */
.team .is-hit { animation: team-hit 1.1s var(--ease); }
@keyframes team-hit { from { box-shadow: 0 0 0 2px var(--d-signal); } to { box-shadow: 0 0 0 2px transparent; } }

/* ---- Erklärung und Knöpfe ------------------------------------------------ */
.team-foot { border-top: 1px solid var(--d-line); }
.team-say {
  min-height: 3.1em;
  margin: 0.9rem var(--t-gap);
  max-width: 48rem;
  font-size: 1.02rem;
  line-height: 1.5;
  color: var(--c-dark-ink);
  text-wrap: pretty;
}
.team-controls { border-top: 1px solid var(--d-line); border-bottom: 0; }
.team-controls .team-label { margin-right: 0.4rem; }
.team-controls .demo-btn:not(.team-toggle):not(:disabled) { color: var(--d-no); border-color: color-mix(in srgb, var(--d-no) 45%, transparent); }
.team-controls .demo-btn:not(.team-toggle):not(:disabled):hover { background: var(--d-no); color: var(--c-dark); }
.team-toggle { margin-left: auto; }

@media (max-width: 1080px) {
  .team-board { grid-template-columns: 12rem minmax(3rem, 1fr) minmax(0, 30rem); }
}
/* Schmal: das Protokoll rutscht unter den Zustand */
@media (max-width: 900px) {
  .team-board { grid-template-columns: 11rem minmax(2.5rem, 1fr) minmax(0, 20rem); }
  .team-live { grid-template-columns: minmax(0, 1fr); }
  .team-phase { white-space: normal; }
  .team-log { border-left: 0; border-top: 1px solid var(--d-line); }
  .team-feed { height: 8.2rem; min-height: 0; }
}
@media (max-width: 560px) {
  .team { --t-gap: 0.75rem; }
  .team-board { grid-template-columns: 7.4rem minmax(1.5rem, 1fr) minmax(0, 11.6rem); }
  .team-agent { grid-template-columns: auto minmax(0, 1fr); align-content: center; gap: 0.35rem 0.45rem; padding: 0.5rem 0.5rem 0.8rem; }
  .team-agent .who { grid-row: auto; }
  .team-agent b { font-size: 0.74rem; line-height: 1.15; white-space: normal; }
  .team-phase { grid-column: 1 / -1; font-size: 0.64rem; min-height: 2.7em; }
  .team-state { padding: 0.75rem 0.65rem; }
  .team-log { padding-left: 0.65rem; }
  .team-feed { font-size: 0.68rem; }
  .team-feed li { white-space: normal; flex-wrap: wrap; gap: 0 0.4em; }
  .team-db { grid-template-columns: 1fr auto; gap: 0.5rem; padding: 0.6rem 0.65rem; font-size: 0.66rem; }
  .team-tape { grid-column: 1 / -1; grid-row: 2; }
  .team-packet:not(:empty) { width: 9px; height: 9px; padding: 0; font-size: 0; }
  .team-say { min-height: 6.2em; font-size: 0.95rem; }
  .team-controls .team-label { width: 100%; }
  .team-toggle { margin-left: 0; }
}
@media (max-width: 360px) {
  .team { --t-gap: 0.6rem; }
  .team-board { grid-template-columns: 5.9rem minmax(1rem, 1fr) minmax(0, 8.9rem); }
  .team-agent { padding-inline: 0.35rem; }
  .team-agent b { font-size: 0.68rem; }
  .team-files code { font-size: 0.7rem; }
  .team-state, .team-log, .team-db { padding-inline: 0.5rem; }
  .team-db { grid-template-columns: 1fr; }
  .team-tape { grid-row: auto; }
}
