/* =====================================================================
   Stage — the app's surfaces as the app draws them, and scenes to put
   them in.

   Two jobs, loaded after theme.css so it has the last word:

   1. The panels look like app.flowguard.run (DESIGN.md "Instrument" in the
      Cloud repo): paper ground and white surfaces in light, ink in dark,
      the deep navy sidebar as the chassis in both, cyan as the one signal,
      tinted status squares, sans-serif text with mono only for code.

   2. Scenes: instead of text left, panel right, flipped for the next
      section, a chapter is a claim on top, a composition of surfaces
      layered the way they pile up on a screen, and its facts as one row.
   ===================================================================== */

/* --- 1. Instrument tokens ----------------------------------------------- */
.appui,
:root[data-theme="light"] .appui {
    --fg-accent: #06b6d4;
    --fg-accent-text: #0e7490;
    --fg-accent-wash: rgba(6, 182, 212, 0.10);
    --fg-bg-primary: #f3f6fa;
    --fg-bg-secondary: #ffffff;
    --fg-bg-elevated: #ffffff;
    --fg-bg-surface: #ffffff;
    --fg-bg-inset: #eef2f7;
    --fg-text-primary: #0b1b2b;
    --fg-text-secondary: #3d5670;
    --fg-text-muted: #7a8ea5;
    --fg-border: rgba(11, 27, 43, 0.09);
    --fg-success: #12a66b;
    --fg-warning: #d98a06;
    --fg-danger: #e0452b;
    --fg-running: #2f7ff5;
    --fg-shadow: 0 1px 2px rgba(11, 27, 43, 0.06), 0 12px 32px -24px rgba(11, 27, 43, 0.28);
    --fg-shadow-float: 0 2px 6px rgba(11, 27, 43, 0.06), 0 30px 60px -28px rgba(11, 27, 43, 0.45);

    border-radius: 14px;
    border-color: var(--fg-border);
    background: var(--fg-bg-secondary);
    box-shadow: var(--fg-shadow);
    font-family: inherit;
}
:root:not([data-theme="light"]) .appui {
    --fg-accent: #22d3ee;
    --fg-accent-text: #67e8f9;
    --fg-accent-wash: rgba(34, 211, 238, 0.12);
    --fg-bg-primary: #070c15;
    --fg-bg-secondary: #0c1422;
    --fg-bg-elevated: #111b2c;
    --fg-bg-surface: #111b2c;
    --fg-bg-inset: #0a111d;
    --fg-text-primary: #eef3f8;
    --fg-text-secondary: #a9b8ca;
    --fg-text-muted: #6c7f96;
    --fg-border: rgba(255, 255, 255, 0.07);
    --fg-success: #34d399;
    --fg-warning: #fbbf24;
    --fg-danger: #f87171;
    --fg-running: #60a5fa;
    --fg-shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 16px 40px -24px rgba(0, 0, 0, 0.6);
    --fg-shadow-float: 0 2px 8px rgba(0, 0, 0, 0.4), 0 34px 70px -30px rgba(0, 0, 0, 0.8);
}

/* The sidebar is the chassis: deep navy in both modes, as in the app. */
.appui .appui-side,
:root[data-theme="light"] .appui .appui-side {
    background: linear-gradient(180deg, #0c1c33 0%, #0a1628 60%, #08121f 100%);
    border-right: 0;
    color: #eef3f8;
}
.appui .appui-brand { color: #fff; }
.appui .appui-nav a { color: rgba(226, 236, 246, 0.62); }
.appui .appui-nav a.is-active { color: #fff; background: rgba(34, 211, 238, 0.12); }
.appui .appui-nav a.is-active::before { background: #22d3ee; box-shadow: 0 0 10px #22d3ee; }
.appui .appui-main { background: var(--fg-bg-primary); }

/* Surfaces inside a window sit one step up from the ground. */
.appui .appui-card,
.appui .appui-stat { background: var(--fg-bg-secondary); border-color: var(--fg-border); border-radius: 12px; box-shadow: var(--fg-shadow); }
.appui .appui-stats { gap: 0; background: var(--fg-bg-secondary); border: 1px solid var(--fg-border); border-radius: 12px; box-shadow: var(--fg-shadow); }
.appui .appui-stats .appui-stat { border: 0; border-radius: 0; box-shadow: none; background: transparent; border-left: 1px solid var(--fg-border); }
.appui .appui-stats .appui-stat:first-child { border-left: 0; }
.appui .appui-stat strong { font-size: 22px; }

/* Type: the app's, sans-serif; mono stays for versions and code. */
.appui .ui-head { padding: 15px 18px; }
.appui .ui-head h4,
.appui .appui-cardhead h4 { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.appui .ui-what strong { font-size: 13.5px; }
.appui .ui-what em,
.appui .appui-what span,
.appui .appui-url { font-family: inherit; font-size: 12px; }
.appui .ui-right { font-family: inherit; font-variant-numeric: tabular-nums; font-size: 12px; }
.appui .ui-foot,
.appui .appui-foot { font-family: inherit; font-size: 12px; }

/* Status: tinted squares, like the executions list. */
.appui .ui-tick { width: 26px; height: 26px; border-radius: 8px; background: rgba(18, 166, 107, 0.12); color: var(--fg-success); }
.appui .ui-tick svg { width: 13px; height: 13px; }
.appui .ui-tick.is-undo { background: rgba(217, 138, 6, 0.13); color: var(--fg-warning); }
.appui .appui-icon { width: 30px; height: 30px; border-radius: 9px; }

/* Chips: pills with a wash, the app's states. */
.appui .appui-badge,
:root[data-theme="light"] .appui .appui-badge { border: 0; border-radius: 999px; padding: 3px 10px; font-size: 11.5px; font-weight: 600; background: var(--fg-bg-inset); color: var(--fg-text-secondary); }
.appui .appui-badge--ok,
:root[data-theme="light"] .appui .appui-badge--ok { background: rgba(18, 166, 107, 0.12); color: var(--fg-success); }
.appui .appui-badge--warn,
:root[data-theme="light"] .appui .appui-badge--warn { background: rgba(217, 138, 6, 0.13); color: var(--fg-warning); }
.appui .appui-badge--fail,
:root[data-theme="light"] .appui .appui-badge--fail { background: rgba(224, 69, 43, 0.12); color: var(--fg-danger); }
:root[data-theme="light"] .appui .appui-badge--ok { color: #0f8a59; }
:root[data-theme="light"] .appui .appui-badge--warn { color: #a86a04; }
.appui .appui-badge--count { background: #22d3ee; color: #062330; }
/* A count in the sidebar is a quiet tally on the navy, not a pill from the
   light content area (that light rule outranked it before). */
.appui .appui-nav .appui-badge--count,
:root[data-theme="light"] .appui .appui-nav .appui-badge--count {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 20px; height: 20px; padding: 0 6px; border-radius: 6px;
    background: rgba(34, 211, 238, 0.14); color: #67e8f9;
    font-size: 11px; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums;
}

/* Buttons: ink-filled primary, hairline secondary. */
.appui .appui-btn { border-radius: 9px; padding: 7px 13px; font-size: 12px; font-weight: 600; background: var(--fg-text-primary); color: var(--fg-bg-secondary); }
.appui .appui-btn--ghost { background: transparent; color: var(--fg-text-secondary); border: 1px solid var(--fg-border); }


/* --- 2. Scenes: one screen, anchored notes ----------------------------
   Grammar (one for all five chapters):
   - The screen takes 8 of 12 columns, left or right; the remaining four
     are the lane where notes live. Monitoring is the one centred screen,
     and its note hangs under it.
   - A note docks to the row it explains: its top meets the row's top, a
     hairline leader with a signal dot runs from the row, and the row is
     tinted. Notes never cover the screen.
   - No rotation, no stacked "back" cards, no free-floating stickers.
   - Without the script, and below 960px, notes sit under the screen with
     a notch pointing up at it.
   ---------------------------------------------------------------------- */
.stage { position: relative; padding: clamp(88px, 10vw, 144px) 0 clamp(72px, 8vw, 112px); border-top: 1px solid var(--hairline); }
.stage-alt { background: var(--w012); }

.stage-head {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    column-gap: 24px;
    align-items: end;
    margin-bottom: clamp(44px, 5vw, 72px);
}
.stage-head h2 { grid-column: 1 / span 6; margin: 0; font-size: clamp(2.4rem, 4.8vw, 3.75rem); font-weight: 700; letter-spacing: -0.04em; line-height: 0.98; }
.stage-lead { grid-column: 7 / -1; }
.stage-lead p { margin: 0; font-size: 1.0625rem; line-height: 1.65; color: var(--text-secondary); max-width: 54ch; text-wrap: pretty; }
.stage-lead .stage-when {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 12px;
    font-family: var(--font-mono);
    font-size: 12.5px;
    letter-spacing: 0;
    color: var(--text-muted);
}
.stage-when span { width: 7px; height: 7px; border-radius: 50%; background: var(--stage-signal); box-shadow: 0 0 0 4px var(--stage-signal-wash); }

:root { --stage-signal: #22d3ee; --stage-signal-wash: rgba(34, 211, 238, 0.16); --stage-leader: rgba(34, 211, 238, 0.7); }
:root[data-theme="light"] { --stage-signal: #0891b2; --stage-signal-wash: rgba(6, 182, 212, 0.14); --stage-leader: rgba(8, 145, 178, 0.55);
    /* The charts read these: cyan like the app, not the site's blue. */
    --chart-accent: #0891b2; --chart-accent-soft: rgba(6, 182, 212, 0.18); }

/* The scene: the 12-column field */
.stage-scene { position: relative; display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); column-gap: 24px; align-items: start; }
.stage-main { position: relative; z-index: 2; grid-row: 1; }
.stage-main > .appui, .stage-main > .agent-wrap > .appui { box-shadow: var(--fg-shadow-float); }
.stage-scene--left .stage-main { grid-column: 1 / span 8; }
.stage-scene--right .stage-main { grid-column: 5 / -1; }
.stage-scene--centre .stage-main { grid-column: 2 / span 10; }

/* Notes: in flow by default (narrow screens, no script) */
.stage-note { position: relative; z-index: 3; grid-column: 1 / -1; margin-top: 22px; max-width: 460px; }
.stage-scene--right .stage-note { justify-self: end; }
.stage-note::before {
    /* the notch: points up at the screen the note belongs to */
    content: ""; position: absolute; top: -7px; left: 28px;
    width: 12px; height: 12px; transform: rotate(45deg);
    background: var(--note-bg, #fff);
    border-left: 1px solid var(--hairline); border-top: 1px solid var(--hairline);
}
:root:not([data-theme="light"]) .stage-note { --note-bg: #0c1422; }
.stage-note--part::before { display: none; }

/* Composed: the script has docked each note to its row */
.stage-scene.is-composed .stage-note { position: absolute; margin: 0; max-width: none; grid-column: auto; }
.stage-scene.is-composed .stage-note::before { display: none; }

.stage-leader { position: absolute; z-index: 1; height: 1px; background: var(--stage-leader); pointer-events: none; }
.stage-leader::before, .stage-leader::after { content: ""; position: absolute; top: -3px; width: 7px; height: 7px; border-radius: 50%; background: var(--stage-signal); box-shadow: 0 0 0 4px var(--stage-signal-wash); display: none; }
.stage-leader.is-start-dot::before { display: block; left: -3px; }
.stage-leader.is-end-dot::after { display: block; right: -3px; }
.stage-leader.is-vertical { width: 1px; height: auto; }
.stage-leader.is-vertical::before { display: block; left: -3px; top: -3px; }

/* The row a note talks about */
.appui .is-anchored { position: relative; background: var(--fg-accent-wash); }
.appui .ui-row.is-anchored, .appui .agent-tool.is-anchored { box-shadow: inset 0 0 0 1px rgba(6, 182, 212, 0.35); }
.appui .appui-strip i.is-anchored { outline: 2px solid var(--stage-signal); outline-offset: 2px; border-radius: 2px; }
.appui .rep-stats.is-anchored { box-shadow: inset 0 0 0 1px rgba(6, 182, 212, 0.3); }

/* Note kinds: each drawn as the thing it is */
.note-toast { display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px 14px 14px; box-shadow: var(--fg-shadow-float); }
.note-toast-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.note-toast-text strong { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; color: var(--fg-text-primary); }
.note-toast-text em { font-style: normal; font-size: 12.5px; line-height: 1.5; color: var(--fg-text-secondary); }

.note-glyph { width: 32px; height: 32px; flex: none; display: grid; place-items: center; border-radius: 9px; }
.note-glyph svg { width: 16px; height: 16px; }
.note-glyph.tone-ok { background: rgba(18, 166, 107, 0.12); color: var(--fg-success); }
.note-glyph.tone-fail { background: rgba(224, 69, 43, 0.12); color: var(--fg-danger); }
.note-glyph.tone-warn { background: rgba(217, 138, 6, 0.13); color: var(--fg-warning); }
.note-glyph.tone-info { background: var(--fg-accent-wash); color: var(--fg-accent-text); }

.note-mail { box-shadow: var(--fg-shadow-float); }
.note-mail-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 14px; background: var(--fg-bg-inset); border-bottom: 1px solid var(--fg-border); font-size: 12px; color: var(--fg-text-muted); }
.note-mail-from b { font-weight: 600; color: var(--fg-text-secondary); }
.note-mail-time { font-variant-numeric: tabular-nums; }
.note-mail-body { display: flex; gap: 12px; padding: 14px 16px 16px 14px; }
.note-mail-subject { display: block; font-size: 15px; font-weight: 600; letter-spacing: -0.012em; line-height: 1.3; color: var(--fg-text-primary); margin: 5px 0 6px; }
.note-mail-body p { margin: 0; font-size: 13px; line-height: 1.55; color: var(--fg-text-secondary); }
.note-file { display: inline-flex; align-items: center; gap: 8px; margin-top: 12px; padding: 7px 11px; border: 1px solid var(--fg-border); border-radius: 9px; font-size: 12px; color: var(--fg-text-secondary); background: var(--fg-bg-secondary); }
.note-file svg { width: 15px; height: 15px; color: var(--fg-danger); }
.note-cta { display: inline-flex; margin-top: 12px; padding: 7px 13px; border-radius: 9px; font-size: 12px; font-weight: 600; background: var(--fg-text-primary); color: var(--fg-bg-secondary); }

.stage-note--part > .appui { box-shadow: var(--fg-shadow-float); }

/* The report reads as a page: portrait, with paper margins */
.stage-scene--left .stage-main:has(.rep-cover) { grid-column: 2 / span 6; }

/* Facts: one row under the scene */
.stage-facts {
    list-style: none;
    margin: clamp(56px, 6vw, 88px) 0 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(var(--facts-cols, 4), minmax(0, 1fr));
    gap: 32px 24px;
}
.stage-facts li { position: relative; padding-top: 18px; border-top: 1px solid var(--hairline); }
.stage-facts b { display: block; font-size: 0.9375rem; font-weight: 600; letter-spacing: -0.01em; color: var(--text-primary); margin-bottom: 6px; }
.stage-facts span { display: block; font-size: 0.875rem; line-height: 1.6; color: var(--text-muted); text-wrap: pretty; }

@media (max-width: 959px) {
    .stage-head { grid-template-columns: minmax(0, 1fr); row-gap: 20px; }
    .stage-head h2, .stage-lead { grid-column: 1 / -1; }
    .stage-scene { display: flex; flex-direction: column; align-items: stretch; }
    .stage-main { width: 100%; }
    .stage-note { max-width: none; }
    .stage-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
    .stage-facts { grid-template-columns: minmax(0, 1fr); }
}

/* A surface of the app docked as a note sits in a narrow lane: the title
   keeps one line and the badge drops under it, the new selector wraps
   instead of being cut off. */
.stage-note .appui-cardhead { flex-wrap: wrap; row-gap: 6px; }
.stage-note .appui-cardhead h4 { white-space: nowrap; flex: 1 1 auto; }
.stage-note .appui-diff code { white-space: normal; overflow-wrap: anywhere; text-overflow: clip; }
