/* React Flow theming /infra — style soft, cards en deux bandeaux,
   blobs flous animés en background, edges dashed animées. */

:root {
    --rf-card-bg: #16161c;
    --rf-card-head: #1d1d25;
    --rf-card-border: #232330;
    --rf-card-border-soft: #1c1c24;
    --rf-edge: rgba(160, 168, 200, 0.35);
}

.rf-frame {
    position: relative;
    margin: 2.5rem 0;
    height: 640px;
    background: var(--bg);
    border: 1px solid var(--rf-card-border-soft);
    border-radius: 14px;
    overflow: hidden;
    isolation: isolate;
}

/* Blobs flous animés derrière la canvas */
.rf-frame::before,
.rf-frame::after {
    content: '';
    position: absolute;
    width: 460px;
    height: 460px;
    border-radius: 50%;
    filter: blur(110px);
    opacity: 0.32;
    pointer-events: none;
    z-index: 0;
    will-change: transform;
}
.rf-frame::before {
    background: var(--accent, #5b8def);
    top: -160px;
    left: 28%;
    animation: rf-blob-a 22s ease-in-out infinite alternate;
}
.rf-frame::after {
    background: #c89a4a;
    bottom: -180px;
    right: 8%;
    opacity: 0.22;
    animation: rf-blob-b 28s ease-in-out infinite alternate;
}
@keyframes rf-blob-a {
    from { transform: translate(0, 0) scale(1); }
    to   { transform: translate(120px, 80px) scale(1.1); }
}
@keyframes rf-blob-b {
    from { transform: translate(0, 0) scale(1); }
    to   { transform: translate(-140px, -60px) scale(0.95); }
}
@media (prefers-reduced-motion: reduce) {
    .rf-frame::before, .rf-frame::after { animation: none; }
}

/* React Flow built-in surfaces */
.rf-frame .react-flow {
    background: transparent;
    position: relative;
    z-index: 1;
}
.rf-frame .react-flow__renderer { background: transparent; }
.rf-frame .react-flow__background { opacity: 0.55; }

.rf-frame .react-flow__attribution {
    background: transparent;
    color: var(--text-dim);
    font-family: 'MapleMono', monospace;
    font-size: 0.6rem;
    letter-spacing: 0.04em;
    padding: 4px 10px;
    opacity: 0.5;
}
.rf-frame .react-flow__attribution a {
    color: var(--text-dim);
    text-decoration: none;
}

.rf-frame .react-flow__controls {
    background: var(--rf-card-bg);
    border: 1px solid var(--rf-card-border);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    overflow: hidden;
}
.rf-frame .react-flow__controls-button {
    background: transparent;
    border-bottom: 1px solid var(--rf-card-border);
    color: var(--text-mute);
    width: 28px;
    height: 28px;
}
.rf-frame .react-flow__controls-button:hover {
    background: var(--rf-card-head);
    color: var(--text);
}
.rf-frame .react-flow__controls-button svg { fill: currentColor; }

/* HOST GROUP : étiquette au-dessus, contour très discret */
.rf-host {
    width: 100%;
    height: 100%;
    background: rgba(20, 20, 26, 0.35);
    border: 1px dashed rgba(255, 255, 255, 0.06);
    border-radius: 18px;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    pointer-events: none;
    position: relative;
}
.rf-host-label {
    position: absolute;
    top: -14px;
    left: 22px;
    background: var(--bg);
    padding: 0 12px;
    font-family: 'MapleMono', monospace;
    font-size: 0.7rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--text-mute);
}
.rf-host-label b {
    color: var(--text);
    font-weight: 500;
}

/* STACK NODE : header sombre + body */
.rf-stack {
    width: 220px;
    background: var(--rf-card-bg);
    border: 1px solid var(--rf-card-border);
    border-radius: 10px;
    overflow: hidden;
    box-shadow:
        0 10px 30px rgba(0, 0, 0, 0.35),
        0 1px 0 rgba(255, 255, 255, 0.04) inset;
    transition:
        transform 240ms cubic-bezier(0.34, 1.2, 0.64, 1),
        box-shadow 240ms ease,
        border-color 240ms ease;
}
.rf-stack:hover,
.rf-stack--hover {
    transform: translateY(-2px);
    border-color: var(--accent);
    box-shadow:
        0 16px 40px rgba(0, 0, 0, 0.45),
        0 0 0 1px var(--accent),
        0 0 36px -10px var(--accent);
}

.rf-stack--dim {
    opacity: 0.32;
    transition: opacity 200ms ease;
}
.rf-stack--dim:hover {
    opacity: 1;
}

.rf-stack-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 8px 12px 7px;
    background: var(--rf-card-head);
    border-bottom: 1px solid var(--rf-card-border);
}
.rf-stack-name {
    font-family: 'MapleMono', monospace;
    font-size: 0.78rem;
    color: var(--text);
    letter-spacing: -0.005em;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.rf-stack-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: rgba(160, 168, 200, 0.4);
    flex-shrink: 0;
}
.rf-stack-dot--ok {
    background: #87b09d;
    box-shadow: 0 0 0 0 rgba(135, 176, 157, 0.5);
    animation: rf-pulse-ok 2.6s ease-out infinite;
}
.rf-stack-dot--warn {
    background: #f0c878;
    box-shadow: 0 0 0 0 rgba(240, 200, 120, 0.5);
    animation: rf-pulse-warn 1.8s ease-out infinite;
}
@keyframes rf-pulse-ok {
    0%   { box-shadow: 0 0 0 0 rgba(135, 176, 157, 0.45); }
    70%  { box-shadow: 0 0 0 6px rgba(135, 176, 157, 0); }
    100% { box-shadow: 0 0 0 0 rgba(135, 176, 157, 0); }
}
@keyframes rf-pulse-warn {
    0%   { box-shadow: 0 0 0 0 rgba(240, 200, 120, 0.5); }
    70%  { box-shadow: 0 0 0 8px rgba(240, 200, 120, 0); }
    100% { box-shadow: 0 0 0 0 rgba(240, 200, 120, 0); }
}
@media (prefers-reduced-motion: reduce) {
    .rf-stack-dot--ok, .rf-stack-dot--warn { animation: none; }
}

.rf-stack-body {
    padding: 9px 12px 11px;
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-family: 'MapleMono', monospace;
    font-size: 0.76rem;
    color: var(--text-mute);
}
.rf-stack-count {
    font-size: 1.05rem;
    color: var(--text);
    font-weight: 500;
    letter-spacing: -0.01em;
}
.rf-stack-suffix {
    font-size: 0.7rem;
    color: var(--text-dim);
    letter-spacing: 0.02em;
}

/* Handles : petits points discrets */
.rf-frame .react-flow__handle {
    background: var(--rf-card-border);
    border: 1px solid var(--rf-card-bg);
    width: 8px;
    height: 8px;
    opacity: 0;
    transition: opacity 200ms ease;
}
.rf-stack:hover ~ * .react-flow__handle,
.rf-frame .react-flow__node:hover .react-flow__handle {
    opacity: 1;
}

/* Edges — couleur + glow passés inline depuis le JS, on contrôle pattern et
   anim. Pattern un peu plus marqué pour bien lire les arcs. */
.rf-frame .react-flow__edge-path {
    stroke-dasharray: 7 5;
    transition: stroke-opacity 220ms ease, stroke-width 220ms ease;
}
.rf-frame .react-flow__edge.animated .react-flow__edge-path {
    animation: rf-dash 1.2s linear infinite;
}
.rf-frame .react-flow__edges {
    /* assure que les edges passent au-dessus du background mais sous les nodes
       (les nodes ont leur propre stacking context) */
    z-index: 1;
}
.rf-frame .react-flow__edge-textbg {
    rx: 3;
}
@keyframes rf-dash {
    from { stroke-dashoffset: 20; }
    to   { stroke-dashoffset: 0; }
}
@media (prefers-reduced-motion: reduce) {
    .rf-frame .react-flow__edge.animated .react-flow__edge-path { animation: none; }
}

/* Fallback texte (a11y / no-JS) */
.rf-fallback {
    margin: 1rem 0 0;
    padding: 0.8rem 1rem;
    background: var(--bg-soft);
    border-left: 2px solid var(--accent);
    font-size: 0.86rem;
    border-radius: 0 4px 4px 0;
}
.rf-fallback summary {
    cursor: pointer;
    color: var(--text);
    font-family: 'MapleMono', monospace;
    font-size: 0.78rem;
    letter-spacing: 0.04em;
}
.rf-fallback ul {
    margin-top: 0.6rem;
    padding-left: 1.2rem;
    color: var(--text-mute);
}
.rf-fallback li { margin-bottom: 0.3rem; }
.rf-fallback code {
    color: var(--text-dim);
    font-size: 0.78rem;
}
