/* ClearRun catalogue demos — family components.
 *
 * One stylesheet shared across all six demo families. Each family is scoped
 * under its own .demo-{family} class. We deliberately keep this OUT of
 * catalogue.css to honour the "do not modify shared CSS" rule from the
 * 2026-05-05 catalogue-finalise build brief.
 *
 * Tokens consumed (from styles.css :root):
 *   --navy, --navy-light, --navy-dark
 *   --accent, --accent-hover, --accent-light
 *   --white, --off-white, --light-grey, --mid-grey
 *   --text, --text-light, --text-on-dark
 *   --radius-sm, --radius-md, --radius-lg
 *   --shadow-sm, --shadow-md, --shadow-lg
 */

/* ---------- Demo stage shell (shared) ---------- */

.demo-stage {
    background: linear-gradient(160deg, var(--navy) 0%, var(--navy-light) 100%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-lg);
    padding: 32px 24px;
    margin: 24px auto;
    max-width: 720px;
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

/* Wrapper just sets sizing; layout belongs to each family.
   Forcing flex here used to collapse conversational chrome. */
.demo-stage > [class*="demo-"] {
    width: 100%;
    min-height: 240px;
}

.detail-demo__caption {
    text-align: center;
    color: var(--text-on-dark);
    font-size: 13px;
    margin-top: 16px;
    opacity: 0.8;
}

@media (max-width: 480px) {
    .demo-stage { padding: 20px 14px; margin: 18px auto; border-radius: var(--radius-md); }
    .demo-stage > [class*="demo-"] { min-height: 220px; }
}

/* If a family JS has not run yet (e.g. the host hasn't entered the viewport),
 * the family root sits empty. Show a quiet placeholder rather than collapsed
 * white space. Only the top-level family root gets this — using the data-*
 * attribute makes the selector specific and avoids matching stray inner
 * elements that briefly start empty (e.g. demo-widget mounting). */
.demo-stage > [data-demo-family]:empty::before {
    content: "Demo loading…";
    color: var(--text-on-dark);
    opacity: 0.5;
    font-size: 13px;
    letter-spacing: 0.04em;
    display: block;
    text-align: center;
    padding: 40px 0;
}

/* ============================================================
 * FAMILY 1 — conversational
 * Wraps the existing demo-widget. CSS lives in demo-widget.css;
 * we only own the surrounding chrome (prompt buttons + frame).
 * ============================================================ */

/* The host stays transparent so the navy demo-stage shows through if the
   widget hasn't mounted yet — avoids the "stark white rectangle" empty
   state. The white background + border move down onto the inner element
   that wraps the chrome+prompts+widget once renderChrome() runs. */
.demo-conversational {
    display: block;
    background: transparent;
    width: 100%;
}

/* Implicit child wrapper: the chrome itself owns the top of the white
   card, the prompts the middle, and the widget the bottom. Together they
   read as a single rounded card without needing an extra wrapper div. */
.demo-conversational__chrome {
    background: linear-gradient(180deg, #F2F4F8 0%, var(--off-white) 100%);
    border: 1px solid var(--mid-grey);
    border-bottom: 1px solid var(--mid-grey);
    border-top-left-radius: var(--radius-md);
    border-top-right-radius: var(--radius-md);
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.demo-conversational__avatar {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--white);
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 14px;
    letter-spacing: 0.04em;
    flex-shrink: 0;
}

.demo-conversational__biz { display: flex; flex-direction: column; flex: 1; min-width: 120px; }
.demo-conversational__biz-name { font-weight: 600; color: var(--navy); font-size: 14px; }
.demo-conversational__biz-status { color: var(--text-light); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.demo-conversational__pulse {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--accent); display: inline-block;
    animation: demo-conv-pulse 1.6s ease-in-out infinite;
}
@keyframes demo-conv-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(26, 158, 143, 0.5); }
    50% { box-shadow: 0 0 0 6px rgba(26, 158, 143, 0); }
}
.demo-conversational__channel {
    font-size: 12px; color: var(--text-light);
    background: var(--white); border: 1px solid var(--mid-grey);
    padding: 4px 10px; border-radius: 999px;
}

.demo-conversational__prompts {
    background: var(--off-white);
    border-left: 1px solid var(--mid-grey);
    border-right: 1px solid var(--mid-grey);
    border-bottom: 1px solid var(--mid-grey);
    padding: 12px 16px;
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
}
.demo-conversational__prompts-label {
    font-size: 12px; color: var(--text-light); margin-right: 4px; flex-basis: 100%; margin-bottom: 4px;
}
.demo-conversational__prompt {
    appearance: none; -webkit-appearance: none;
    background: var(--white); color: var(--navy);
    border: 1px solid var(--mid-grey);
    border-radius: 999px;
    padding: 6px 12px; font-size: 12px;
    cursor: pointer; transition: all var(--transition);
}
.demo-conversational__prompt:hover { border-color: var(--accent); color: var(--accent); }

.demo-conversational__widget {
    padding: 0;
    min-height: 280px;
    background: var(--white);
    border: 1px solid var(--mid-grey);
    border-top: none;
    border-bottom-left-radius: var(--radius-md);
    border-bottom-right-radius: var(--radius-md);
    overflow: hidden;
}

@media (max-width: 480px) {
    .demo-conversational__chrome { padding: 12px 14px; gap: 10px; }
    .demo-conversational__avatar { width: 36px; height: 36px; font-size: 13px; }
    .demo-conversational__channel { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .demo-conversational__pulse { animation: none; }
}

/* ============================================================
 * FAMILY 2 — document-flow
 * Input artefact card → processing pulse → output card with
 * extracted values appearing line by line. 7s loop.
 * ============================================================ */

.demo-document-flow {
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px; width: 100%; padding: 8px;
    flex-wrap: wrap;
}

.demo-document-flow__card {
    flex: 1 1 200px;
    background: var(--white);
    color: var(--navy);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: var(--shadow-md);
    min-width: 0;
}

.demo-document-flow__label {
    font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--text-light); display: block; margin-bottom: 8px;
    font-weight: 600;
}

.demo-document-flow__title {
    font-size: 14px; font-weight: 600; color: var(--navy);
    margin-bottom: 10px; padding-bottom: 8px;
    border-bottom: 1px solid var(--light-grey);
}

.demo-document-flow__row {
    display: flex; justify-content: space-between; align-items: baseline;
    font-size: 12px; padding: 4px 0;
    color: var(--text);
    opacity: 0;
    animation: demo-df-row 7s ease-in-out infinite;
}

.demo-document-flow--input .demo-document-flow__row {
    opacity: 1;
    animation: none;
}

.demo-document-flow__row .key { color: var(--text-light); }
.demo-document-flow__row .val { font-weight: 600; color: var(--navy); }
.demo-document-flow__row.is-accent .val { color: var(--accent); }

.demo-document-flow__processor {
    flex: 0 0 auto;
    width: 56px; height: 56px;
    border-radius: 50%;
    background: rgba(26, 158, 143, 0.18);
    border: 1px solid var(--accent);
    display: flex; align-items: center; justify-content: center;
    position: relative;
    color: var(--accent);
}

.demo-document-flow__processor::before,
.demo-document-flow__processor::after {
    content: ""; position: absolute; inset: -4px;
    border-radius: 50%; border: 1px solid var(--accent);
    opacity: 0;
    animation: demo-df-pulse 7s ease-out infinite;
}
.demo-document-flow__processor::after { animation-delay: 1s; }

@keyframes demo-df-pulse {
    0%, 14% { opacity: 0; transform: scale(1); }
    28% { opacity: 0.6; transform: scale(1); }
    50% { opacity: 0; transform: scale(1.6); }
    100% { opacity: 0; transform: scale(1.6); }
}

@keyframes demo-df-row {
    0%, 35% { opacity: 0; transform: translateY(4px); }
    50% { opacity: 1; transform: translateY(0); }
    95% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(0); }
}

@media (max-width: 480px) {
    .demo-document-flow { flex-direction: column; gap: 10px; }
    .demo-document-flow__processor { transform: rotate(90deg); width: 44px; height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
    .demo-document-flow__row,
    .demo-document-flow__processor::before,
    .demo-document-flow__processor::after { animation: none; opacity: 1; }
    .demo-document-flow__processor::before,
    .demo-document-flow__processor::after { display: none; }
}

/* ============================================================
 * FAMILY 3 — trigger-action
 * Event icon pulses on left → travelling line → action icon
 * materialises on right with a small detail panel. 6s loop.
 * ============================================================ */

.demo-trigger-action {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 16px;
    width: 100%; padding: 8px;
}

.demo-trigger-action__node {
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    min-width: 96px;
}

.demo-trigger-action__icon {
    width: 64px; height: 64px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.18);
    display: flex; align-items: center; justify-content: center;
    color: var(--white);
    position: relative;
    font-size: 24px;
}

.demo-trigger-action__node--trigger .demo-trigger-action__icon::before {
    content: ""; position: absolute; inset: -6px;
    border-radius: 50%; border: 1.5px solid var(--accent);
    opacity: 0;
    animation: demo-ta-trigger 6s ease-out infinite;
}

@keyframes demo-ta-trigger {
    0%, 80% { opacity: 0; transform: scale(1); }
    5% { opacity: 0.9; transform: scale(1); }
    25% { opacity: 0; transform: scale(1.6); }
}

.demo-trigger-action__label {
    color: var(--white); font-size: 12px; text-align: center;
    line-height: 1.3;
}

.demo-trigger-action__line {
    height: 2px;
    background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.18) 20%, rgba(255, 255, 255, 0.18) 80%, transparent 100%);
    position: relative;
    border-radius: 2px;
}

.demo-trigger-action__line::after {
    content: ""; position: absolute; top: -3px; left: 0;
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 12px var(--accent);
    animation: demo-ta-travel 6s ease-in-out infinite;
}

@keyframes demo-ta-travel {
    0%, 14% { left: 0%; opacity: 0; }
    20% { opacity: 1; }
    50% { left: 100%; opacity: 1; }
    55%, 100% { left: 100%; opacity: 0; }
}

.demo-trigger-action__node--action .demo-trigger-action__icon {
    background: var(--accent);
    border-color: var(--accent);
    opacity: 0.3;
    transform: scale(0.85);
    animation: demo-ta-arrive 6s ease-out infinite;
}

@keyframes demo-ta-arrive {
    0%, 50% { opacity: 0.3; transform: scale(0.85); }
    60% { opacity: 1; transform: scale(1.05); }
    70%, 95% { opacity: 1; transform: scale(1); }
    100% { opacity: 0.3; transform: scale(0.85); }
}

.demo-trigger-action__preview {
    position: absolute; top: calc(100% + 12px); left: 50%;
    transform: translateX(-50%);
    background: var(--white); color: var(--text);
    border-radius: var(--radius-sm);
    padding: 8px 12px; font-size: 11px;
    white-space: nowrap; max-width: 220px;
    overflow: hidden; text-overflow: ellipsis;
    box-shadow: var(--shadow-md);
    opacity: 0;
    animation: demo-ta-preview 6s ease-out infinite;
}

@keyframes demo-ta-preview {
    0%, 60% { opacity: 0; transform: translate(-50%, -4px); }
    72% { opacity: 1; transform: translate(-50%, 0); }
    92% { opacity: 1; transform: translate(-50%, 0); }
    100% { opacity: 0; transform: translate(-50%, 0); }
}

.demo-trigger-action__node--action { position: relative; padding-bottom: 36px; }

@media (max-width: 480px) {
    .demo-trigger-action { grid-template-columns: 1fr; gap: 24px; padding: 12px 4px; }
    .demo-trigger-action__line { height: 36px; width: 2px; margin: 0 auto;
        background: linear-gradient(180deg, transparent 0%, rgba(255,255,255,.2) 20%, rgba(255,255,255,.2) 80%, transparent 100%); }
    .demo-trigger-action__line::after { animation: demo-ta-travel-v 6s ease-in-out infinite; left: -3px; top: 0; }
    @keyframes demo-ta-travel-v {
        0%, 14% { top: 0%; opacity: 0; }
        20% { opacity: 1; }
        50% { top: 100%; opacity: 1; }
        55%, 100% { top: 100%; opacity: 0; }
    }
}

@media (prefers-reduced-motion: reduce) {
    .demo-trigger-action__icon::before,
    .demo-trigger-action__line::after,
    .demo-trigger-action__node--action .demo-trigger-action__icon,
    .demo-trigger-action__preview { animation: none; }
    .demo-trigger-action__node--action .demo-trigger-action__icon { opacity: 1; transform: none; }
    .demo-trigger-action__preview { opacity: 1; transform: translateX(-50%); position: static; margin-top: 8px; }
}

/* ============================================================
 * FAMILY 4 — fan-out
 * One source node → 3-4 output nodes appear in sequence with
 * subtle stagger. 8s loop.
 * ============================================================ */

.demo-fan-out {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 32px;
    align-items: center;
    width: 100%; padding: 8px;
}

.demo-fan-out__source {
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    position: relative;
}

.demo-fan-out__source-icon {
    width: 72px; height: 72px;
    border-radius: var(--radius-md);
    background: var(--accent);
    color: var(--white);
    display: flex; align-items: center; justify-content: center;
    font-size: 28px;
    box-shadow: 0 0 24px rgba(26, 158, 143, 0.4);
}

.demo-fan-out__source-label {
    color: var(--white); font-size: 13px;
    text-align: center; font-weight: 500;
}

.demo-fan-out__targets {
    display: flex; flex-direction: column; gap: 10px;
    position: relative;
}

.demo-fan-out__target {
    display: flex; align-items: center; gap: 10px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    color: var(--white);
    font-size: 13px;
    opacity: 0;
    transform: translateX(-12px);
    animation: demo-fo-target 8s ease-out infinite;
}

.demo-fan-out__target-icon {
    width: 28px; height: 28px;
    border-radius: 6px;
    background: rgba(26, 158, 143, 0.25);
    color: var(--accent);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
}

.demo-fan-out__target:nth-child(1) { animation-delay: 1s; }
.demo-fan-out__target:nth-child(2) { animation-delay: 1.6s; }
.demo-fan-out__target:nth-child(3) { animation-delay: 2.2s; }
.demo-fan-out__target:nth-child(4) { animation-delay: 2.8s; }

@keyframes demo-fo-target {
    0%, 9% { opacity: 0; transform: translateX(-12px); }
    14% { opacity: 1; transform: translateX(0); }
    85% { opacity: 1; transform: translateX(0); }
    100% { opacity: 0; transform: translateX(-12px); }
}

@media (max-width: 480px) {
    .demo-fan-out { grid-template-columns: 1fr; gap: 18px; text-align: center; }
    .demo-fan-out__targets { align-items: stretch; }
    .demo-fan-out__source-icon { width: 60px; height: 60px; }
}

@media (prefers-reduced-motion: reduce) {
    .demo-fan-out__target { animation: none; opacity: 1; transform: none; }
}

/* ============================================================
 * FAMILY 5 — drip-sequence
 * Timeline left-to-right with N stages, current stage highlighted,
 * advancing every 1.5s, looping back to start. 7.5s × 5 stages typical.
 * ============================================================ */

.demo-drip-sequence {
    display: flex; flex-direction: column; gap: 18px;
    width: 100%; padding: 16px 8px;
}

.demo-drip-sequence__cycle {
    color: var(--text-on-dark);
    font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em;
    text-align: center; font-weight: 600;
    opacity: 0.7;
}

.demo-drip-sequence__rail {
    position: relative;
    display: flex; justify-content: space-between;
    padding: 0 12px;
}

.demo-drip-sequence__rail::before {
    content: ""; position: absolute; left: 12px; right: 12px; top: 11px;
    height: 2px; background: rgba(255, 255, 255, 0.12);
}

.demo-drip-sequence__stage {
    position: relative; z-index: 1;
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    flex: 1; min-width: 0;
}

.demo-drip-sequence__dot {
    width: 24px; height: 24px;
    border-radius: 50%;
    background: var(--navy);
    border: 2px solid rgba(255, 255, 255, 0.25);
    transition: all 0.4s ease;
}

.demo-drip-sequence__stage.is-active .demo-drip-sequence__dot {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 0 6px rgba(26, 158, 143, 0.18);
    transform: scale(1.15);
}

.demo-drip-sequence__stage.is-done .demo-drip-sequence__dot {
    background: var(--accent);
    border-color: var(--accent);
}

.demo-drip-sequence__label {
    color: var(--text-on-dark);
    font-size: 11px; text-align: center;
    line-height: 1.3;
    transition: color 0.4s ease;
}

.demo-drip-sequence__stage.is-active .demo-drip-sequence__label {
    color: var(--white); font-weight: 600;
}

.demo-drip-sequence__day {
    color: var(--accent);
    font-size: 10px; text-transform: uppercase;
    letter-spacing: 0.06em; font-weight: 600;
    opacity: 0.7;
}

@media (max-width: 480px) {
    .demo-drip-sequence__label { display: none; }
    .demo-drip-sequence__stage.is-active .demo-drip-sequence__label {
        display: block; position: absolute; bottom: -28px;
        font-size: 12px; white-space: nowrap;
    }
}

@media (prefers-reduced-motion: reduce) {
    .demo-drip-sequence__dot { transition: none; }
}

/* ============================================================
 * FAMILY 6 — research-then-action
 * Query bubble → research card with 2-3 facts populating →
 * personalised output card composing those facts in. 9s loop.
 * ============================================================ */

.demo-research-then-action {
    display: flex; flex-direction: column; gap: 14px;
    width: 100%; padding: 4px;
}

.demo-research-then-action__query {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--white);
    border-radius: 14px 14px 14px 4px;
    padding: 10px 14px;
    max-width: 70%;
    font-size: 13px;
    position: relative;
}

.demo-research-then-action__query::before {
    content: "Query";
    position: absolute; top: -16px; left: 4px;
    font-size: 10px; text-transform: uppercase;
    letter-spacing: 0.08em; color: var(--text-on-dark); opacity: 0.6;
}

.demo-research-then-action__research {
    align-self: flex-end;
    background: var(--white);
    color: var(--navy);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    width: 80%; max-width: 380px;
    box-shadow: var(--shadow-md);
    position: relative;
}

.demo-research-then-action__research::before {
    content: "Research";
    position: absolute; top: -16px; right: 4px;
    font-size: 10px; text-transform: uppercase;
    letter-spacing: 0.08em; color: var(--text-on-dark); opacity: 0.6;
}

.demo-research-then-action__fact {
    display: flex; align-items: baseline; gap: 8px;
    font-size: 12px; padding: 4px 0;
    border-top: 1px solid var(--light-grey);
    opacity: 0;
    animation: demo-rta-fact 9s ease-out infinite;
}
.demo-research-then-action__fact:first-child { border-top: none; }
.demo-research-then-action__fact:nth-child(1) { animation-delay: 0.5s; }
.demo-research-then-action__fact:nth-child(2) { animation-delay: 1.0s; }
.demo-research-then-action__fact:nth-child(3) { animation-delay: 1.5s; }
.demo-research-then-action__fact:nth-child(4) { animation-delay: 2.0s; }

.demo-research-then-action__fact .key {
    color: var(--text-light); flex-shrink: 0; min-width: 90px;
}
.demo-research-then-action__fact .val {
    color: var(--navy); font-weight: 600;
}

/* Each fact slides in once early in the cycle, then stays visible
   right up until the cycle resets — gives a stable picture for most
   of the loop instead of constant fading. */
@keyframes demo-rta-fact {
    0%, 5% { opacity: 0; transform: translateY(2px); }
    15% { opacity: 1; transform: translateY(0); }
    95% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(0); }
}

.demo-research-then-action__output {
    align-self: flex-start;
    background: var(--accent);
    color: var(--white);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    max-width: 90%;
    font-size: 13px;
    line-height: 1.5;
    position: relative;
    opacity: 0;
    animation: demo-rta-output 9s ease-out infinite;
    box-shadow: 0 4px 16px rgba(26, 158, 143, 0.3);
}

.demo-research-then-action__output::before {
    content: "Personalised reply";
    position: absolute; top: -16px; left: 4px;
    font-size: 10px; text-transform: uppercase;
    letter-spacing: 0.08em; color: var(--text-on-dark); opacity: 0.6;
}

/* Output appears after the facts have settled (~3.5s) and stays visible
   for the rest of the cycle. */
@keyframes demo-rta-output {
    0%, 30% { opacity: 0; transform: translateY(6px); }
    40% { opacity: 1; transform: translateY(0); }
    95% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(0); }
}

@media (max-width: 480px) {
    .demo-research-then-action__research { width: 95%; }
    .demo-research-then-action__output, .demo-research-then-action__query { max-width: 95%; }
}

@media (prefers-reduced-motion: reduce) {
    .demo-research-then-action__fact,
    .demo-research-then-action__output { animation: none; opacity: 1; }
}
