/* ==========================================================================
   chatCOS — Architektur-Blueprint (mehrschichtig, gerichteter Datenfluss)
   Modul: anim-architecture

   Scope: ausschliesslich #anim-architecture. Vier gestapelte Schicht-Baender
   (Eingang, Orchestrierung, Bau & Zustand, Auslieferung) mit Komponenten-Boxen.
   Ein SVG-Overlay zeichnet gerichtete Konnektoren mit Pfeilspitzen und
   Kanten-Labels; die Hauptkanten zeichnen sich Schicht fuer Schicht per
   stroke-dashoffset ein, dazu eine gestrichelte Rueckweg-Linie im Rand.

   Farben AUSSCHLIESSLICH ueber globale Contract-Variablen (--accent, --accent-2,
   --accent-soft, --on-accent, --surface, --surface-2, --bg, --text,
   --text-muted, --border). Keine hartkodierten Farben.
   prefers-reduced-motion -> vollstaendiger Endzustand sofort, ohne Bewegung.
   ========================================================================== */

#anim-architecture {
  --bp-ease: cubic-bezier(0.22, 1, 0.36, 1);
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: clamp(6px, 1.5vw, 14px) 0;
}
#anim-architecture *,
#anim-architecture *::before,
#anim-architecture *::after { box-sizing: border-box; }

/* --- Stage --------------------------------------------------------------- */
.bp-stage {
  position: relative;
  width: 100%;
  margin: 0 auto;
}

/* Layer stack. Top/right/bottom padding reserves the feedback-loop lanes
   (the return line runs only in these margins); symmetric left inset gives the
   bands breathing room from the edge. */
.bp-layers {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: clamp(32px, 4.2vw, 48px);
  padding: 34px 34px 34px 34px;
}

/* --- Layer band ---------------------------------------------------------- */
.bp-layer {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface-2) 55%, transparent);
  padding: clamp(13px, 1.8vw, 20px);
  opacity: 0;
  transform: translateY(18px);
  transition:
    opacity 0.6s var(--bp-ease),
    transform 0.6s var(--bp-ease),
    background-color 0.4s var(--bp-ease),
    border-color 0.4s var(--bp-ease);
}
.bp-stage.is-built .bp-layer { opacity: 1; transform: none; }

.bp-layer__head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding-left: 2px;
}
.bp-layer__num {
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 8px;
  border-radius: 6px;
  transition: color 0.4s var(--bp-ease), background-color 0.4s var(--bp-ease);
}
.bp-layer__name {
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text);
}

/* --- Row grid (3 columns; explicit placement keeps the backbone aligned) - */
.bp-layer__row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(18px, 2.8vw, 40px);
  align-items: stretch;
}

/* --- Component box ------------------------------------------------------- */
.bp-box {
  position: relative;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: clamp(12px, 1.5vw, 16px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 26px -22px rgba(10, 22, 44, 0.55);
  opacity: 0;
  transform: translateY(14px) scale(0.98);
  transition:
    opacity 0.5s var(--bp-ease),
    transform 0.5s var(--bp-ease),
    background-color 0.4s var(--bp-ease),
    border-color 0.4s var(--bp-ease),
    box-shadow 0.4s var(--bp-ease);
}
.bp-stage.is-built .bp-box { opacity: 1; transform: none; }

.bp-box[data-col="1"] { grid-column: 1; }
.bp-box[data-col="2"] { grid-column: 2; }
.bp-box[data-col="3"] { grid-column: 3; }

.bp-box__icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  flex: none;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  transition: background-color 0.4s var(--bp-ease), color 0.4s var(--bp-ease);
}
.bp-box__icon svg {
  width: 20px; height: 20px;
  stroke: currentColor; fill: none;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.bp-box__body { min-width: 0; }
.bp-box__title {
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: var(--text);
}
.bp-box__sub {
  font-size: 0.74rem;
  line-height: 1.3;
  color: var(--text-muted);
  margin-top: 2px;
}
.bp-box__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 9px;
}
.bp-chip {
  font-size: 0.66rem;
  font-weight: 500;
  line-height: 1.5;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 1px 7px;
  border-radius: 999px;
  transition: background-color 0.4s var(--bp-ease), border-color 0.4s var(--bp-ease);
}

/* Core / orchestrator box, visually emphasised. */
.bp-box--core {
  background: linear-gradient(180deg, var(--accent-soft), var(--surface));
  border-color: color-mix(in srgb, var(--accent) 34%, var(--border));
  box-shadow: 0 16px 36px -22px color-mix(in srgb, var(--accent) 60%, transparent);
}
.bp-box--core .bp-box__icon { background: var(--accent); color: var(--on-accent); }
.bp-box--core .bp-box__title { font-size: 0.98rem; }

/* --- SVG connector overlay ---------------------------------------------- */
.bp-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
  overflow: visible;
}

.bp-edge {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  /* Verborgen geboren: Slots entstehen als .bp-edge, bevor skinSlot die
     Variante (main/soft/return) setzt. Ohne dies starteten sie bei opacity 1
     und ein verzoegerter (transition-delay) 1->0-Uebergang hielt sie sichtbar,
     sodass v. a. die gestrichelte Rueckweg-Linie der eigenen Schicht vorauseilte. */
  opacity: 0;
}
/* Primary flow edges — draw themselves in via stroke-dashoffset. */
.bp-edge--main {
  stroke: var(--accent);
  stroke-width: 2.4;
  stroke-dasharray: var(--len, 1);
  stroke-dashoffset: var(--len, 1);
  opacity: 0;
  transition:
    stroke-dashoffset 0.72s var(--bp-ease),
    opacity 0.12s var(--bp-ease),
    stroke 0.4s var(--bp-ease);
}
.bp-stage.is-built .bp-edge--main { stroke-dashoffset: 0; opacity: 0.95; }

/* Secondary structural edges — fade in. */
.bp-edge--soft {
  stroke: color-mix(in srgb, var(--text-muted) 82%, var(--text));
  stroke-width: 1.7;
  opacity: 0;
  transition: opacity 0.5s var(--bp-ease), stroke 0.4s var(--bp-ease);
}
.bp-stage.is-built .bp-edge--soft { opacity: 0.72; }
.bp-edge--io { stroke-dasharray: 5 5; }

/* Feedback loop back to the entry channel. */
.bp-edge--return {
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 6 7;
  opacity: 0;
  transition: opacity 0.6s var(--bp-ease), stroke 0.4s var(--bp-ease);
}
.bp-stage.is-built .bp-edge--return { opacity: 0.62; }

/* Arrowheads (fill via contract variables). */
.bp-arrowhead { fill: var(--accent); transition: fill 0.4s var(--bp-ease); }
.bp-arrowhead-soft { fill: color-mix(in srgb, var(--text-muted) 82%, var(--text)); transition: fill 0.4s var(--bp-ease); }

/* --- Edge labels (HTML overlay for crisp, readable chips) ---------------- */
.bp-labels {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}
.bp-label {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.005em;
  line-height: 1.3;
  text-align: center;
  color: var(--text-muted);
  background: color-mix(in srgb, var(--surface) 90%, var(--bg));
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 6px;
  white-space: nowrap;
  max-width: 156px;
  opacity: 0;
  box-shadow: 0 4px 12px -9px rgba(10, 22, 44, 0.6);
  transition: opacity 0.45s var(--bp-ease),
    background-color 0.4s var(--bp-ease), border-color 0.4s var(--bp-ease);
}
.bp-stage.is-built .bp-label { opacity: 1; }
.bp-label--wrap { white-space: normal; }
.bp-label--return { color: var(--accent); }

/* ==========================================================================
   Responsive — stack layers into a single column on narrow screens.
   ========================================================================== */
@media (max-width: 768px) {
  .bp-layers {
    gap: 44px;
    padding: 26px 24px 30px 24px;
  }
  .bp-layer__row {
    grid-template-columns: 1fr;
    gap: 48px;
  }
  .bp-box { grid-column: auto !important; }
  .bp-label { font-size: 0.64rem; max-width: 220px; }
}

/* ==========================================================================
   Reduced motion — full blueprint immediately, no movement, no pulse.
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  #anim-architecture *,
  #anim-architecture *::before,
  #anim-architecture *::after {
    transition: none !important;
    animation: none !important;
  }
  .bp-layer, .bp-box { opacity: 1 !important; transform: none !important; }
  .bp-edge { opacity: 1 !important; }
  .bp-edge--main { stroke-dashoffset: 0 !important; }
  .bp-edge--soft { opacity: 0.72 !important; }
  .bp-edge--return { opacity: 0.62 !important; }
  .bp-label { opacity: 1 !important; }
}

/* Explicit reduced flag (set by JS when it force-shows the end state). */
#anim-architecture.bp-reduced *,
#anim-architecture.bp-reduced *::before,
#anim-architecture.bp-reduced *::after {
  transition: none !important;
  animation: none !important;
}
