/***********************************************************************************
 * CommandEdge: run viewer (stfwRunningViewer) and its stage-detail popup.
 * Classes are added by javascript/stfwRunView.js. Self-contained: loaded by both
 * index.html and workflow.html, so it does not rely on stfwDesigner.css.
 ***********************************************************************************/

.rv, .rv-report, .ldcv.rv-modal {
    --rv-ok: #067647;   --rv-ok-bg: #ecfdf3;
    --rv-warn: orange; --rv-warn-bg: rgba(255, 165, 0, .14);   /* same as the designer's warning connections (was #B54708, read as red) */
    --rv-err: #D92D20;  --rv-err-bg: #fef3f2;
    --rv-run: #1E5BFF;  --rv-run-bg: #EEF2FF;
    --rv-int: #344054;  --rv-int-bg: #f2f4f7;
    --rv-unk: #6941C6;  --rv-unk-bg: #f4f3ff;
    --rv-nodata: #3B7C0F; --rv-nodata-bg: #f3fee7;
    --rv-none: #98A2B3; --rv-off-bg: #f2f4f7;
    --rv-canvas: #fbfcfe; --rv-dot: #d5dde6;
    --rv-card: #ffffff; --rv-card-line: #d5dde6; --rv-card-ink: #0f1d2b;
    font-family: var(--ob-font);
}

/* the viewer modal: full width, content fills it */
.rv { display: flex; flex-direction: column; gap: 14px; height: auto !important; }
.rv > br, .rv > hr { display: none !important; }

/* ---------------------------------------------------------------- stats */
.rv .rv-stats {
    display: grid !important;
    grid-template-columns: repeat(6, minmax(0, 1fr)) !important;
    grid-auto-flow: row;
    gap: 2px 16px !important;
    padding: 14px 18px !important;
    background: var(--ob-head) !important;
    border: 1px solid var(--ob-line);
    border-radius: 12px;
    font-size: 13.5px !important;
}
.rv .rv-stats > div { background: transparent !important; min-width: 0; }
.rv .rv-stats > .rv-k strong {
    font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ob-muted);
}
.rv .rv-stats > .rv-v {
    color: var(--ob-ink); font-weight: 600; font-variant-numeric: tabular-nums;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-top: 2px;
}
.rv .rv-stats > [id^="vwrrequestid"] { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 500; }
.rv .rv-stats > [id^="vwrstatusname"] { justify-self: start; }
.rv .rv-stats > [id^="vwrstatusname"],
.rv-report > .rv-c1 {
    display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 10px !important; border-radius: 999px;
    font-size: 12px; font-weight: 650; line-height: 1;
    background: var(--rv-int-bg) !important; color: var(--rv-int) !important;
}
.rv .rv-stats > [id^="vwrstatusname"]::before,
.rv-report > .rv-c1::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
[data-s="ok"]     { --s: var(--rv-ok);     --s-bg: var(--rv-ok-bg); }
[data-s="warn"]   { --s: var(--rv-warn);   --s-bg: var(--rv-warn-bg); }
[data-s="err"]    { --s: var(--rv-err);    --s-bg: var(--rv-err-bg); }
[data-s="run"],
[data-s="wait"]   { --s: var(--rv-run);    --s-bg: var(--rv-run-bg); }
[data-s="int"]    { --s: var(--rv-int);    --s-bg: var(--rv-int-bg); }
[data-s="unk"]    { --s: var(--rv-unk);    --s-bg: var(--rv-unk-bg); }
[data-s="nodata"] { --s: var(--rv-nodata); --s-bg: var(--rv-nodata-bg); }
.rv .rv-stats > [id^="vwrstatusname"][data-s],
.rv-report > .rv-c1[data-s] { background: var(--s-bg) !important; color: var(--s) !important; }
.rv .rv-stats > [data-s="run"]::before, .rv .rv-stats > [data-s="wait"]::before { animation: rv-pulse 1.2s ease-in-out infinite; }

/* ---------------------------------------------------------------- canvas */
.rv .rv-canvas {
    position: relative;
    width: 100% !important;
    height: min(66vh, 720px) !important;
    margin: 0 !important;
    border: 1px solid var(--ob-line) !important;
    border-radius: 12px;
    background-color: var(--rv-canvas) !important;
    background-image: radial-gradient(var(--rv-dot) 1px, transparent 1.2px);
    background-size: 20px 20px;
    overflow: auto;
}
.rv .rv-hint {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px;
    margin-top: -6px; font-size: 12.5px; color: var(--ob-muted);
}
.rv .rv-hint span { display: inline-flex; align-items: center; gap: 6px; }
.rv .rv-hint i { width: 10px; height: 10px; border-radius: 3px; border: 2px solid var(--rv-none); }
.rv .rv-hint i[data-rs="ok"]   { border-color: var(--rv-ok); }
.rv .rv-hint i[data-rs="warn"] { border-color: var(--rv-warn); }
.rv .rv-hint i[data-rs="err"]  { border-color: var(--rv-err); }
.rv .rv-hint i[data-rs="run"]  { border-color: var(--rv-run); }
.rv .rv-hint em { margin-left: auto; font-style: normal; }

/* step cards. Template children: [0] sftwoin (status colour), [1] sftwoout,
   [2] stfwocenter, [3] stfwoimage, [4] stfwonotif, [5] stfwotitle.
   Steps are the direct children of #viewerplumbarea<run>; the status comes from
   data-rs (stfwRunView.js) and must out-rank the defaults, hence the prefix. */
.rv [id^="viewerplumbarea"] > *                            { --node: #1E5BFF; --rs: var(--rv-none); }   /* defaults: lowest rank */
.rv [id^="viewerplumbarea"] > .jtk-managed:not(.stfwstart) { cursor: pointer; }
.rv [id^="viewerplumbarea"] > .stfwenricher                 { --node: #8B3CF6; }
.rv [id^="viewerplumbarea"] > .stfwmapper,
.rv [id^="viewerplumbarea"] > .stfwvertmapper               { --node: #0E9384; }
.rv [id^="viewerplumbarea"] > [data-rs="ok"]     { --rs: var(--rv-ok);     --rs-bg: var(--rv-ok-bg);     --rs-icon: "✓"; }
.rv [id^="viewerplumbarea"] > [data-rs="warn"]   { --rs: var(--rv-warn);   --rs-bg: var(--rv-warn-bg);   --rs-icon: "!"; }
.rv [id^="viewerplumbarea"] > [data-rs="err"]    { --rs: var(--rv-err);    --rs-bg: var(--rv-err-bg);    --rs-icon: "✕"; }
.rv [id^="viewerplumbarea"] > [data-rs="run"],
.rv [id^="viewerplumbarea"] > [data-rs="wait"]   { --rs: var(--rv-run);    --rs-bg: var(--rv-run-bg);    --rs-icon: "•"; }
.rv [id^="viewerplumbarea"] > [data-rs="int"]    { --rs: var(--rv-int);    --rs-bg: var(--rv-int-bg);    --rs-icon: "■"; }
.rv [id^="viewerplumbarea"] > [data-rs="unk"]    { --rs: var(--rv-unk);    --rs-bg: var(--rv-unk-bg);    --rs-icon: "?"; }
.rv [id^="viewerplumbarea"] > [data-rs="nodata"] { --rs: var(--rv-nodata); --rs-bg: var(--rv-nodata-bg); --rs-icon: "∅"; }

.rv [id^="viewerplumbarea"] > .jtk-managed:not(.stfwstart) > [id^="sftwoin"] {
    background: var(--rv-card) !important;
    border: 2px solid var(--rs) !important;
    border-radius: 12px !important;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 6px 16px -6px rgba(16, 24, 40, .18);
    transition: box-shadow .12s;
}
/* type band along the top, inside the frame */
.rv [id^="viewerplumbarea"] > .jtk-managed:not(.stfwstart) > [id^="sftwoin"]::before {
    content: ""; position: absolute; left: 0; right: 0; top: 0; height: 4px; border-radius: 10px 10px 0 0; background: var(--node);
}
/* status badge on the top-right corner */
.rv [id^="viewerplumbarea"] > .jtk-managed:not(.stfwstart):not([data-rs="none"]) > [id^="sftwoin"]::after {
    content: var(--rs-icon, "");
    position: absolute; top: -9px; right: -9px; z-index: 2;
    width: 20px; height: 20px; border-radius: 50%;
    display: grid; place-items: center;
    font: 800 11px/1 var(--ob-font); color: #fff;
    background: var(--rs);
    box-shadow: 0 0 0 2px var(--rv-card);
}
.rv [id^="viewerplumbarea"] > [data-rs="none"] > [id^="sftwoin"] { border-style: dashed !important; box-shadow: none; }
.rv [id^="viewerplumbarea"] > [data-rs="none"] > [id^="stfwotitle"] { opacity: .55; }
.rv [id^="viewerplumbarea"] > .jtk-managed:not(.stfwstart):hover > [id^="sftwoin"] { box-shadow: 0 0 0 3px color-mix(in srgb, var(--rs) 25%, transparent), 0 8px 20px -6px rgba(16, 24, 40, .25); }
.rv [id^="viewerplumbarea"] > [data-rs="run"] > [id^="sftwoin"],
.rv [id^="viewerplumbarea"] > [data-rs="wait"] > [id^="sftwoin"] { animation: rv-ring 1.4s ease-in-out infinite; }
.rv [id^="viewerplumbarea"] > [data-rs="run"] > [id^="sftwoin"]::after,
.rv [id^="viewerplumbarea"] > [data-rs="wait"] > [id^="sftwoin"]::after { animation: rv-pulse 1.2s ease-in-out infinite; }
/* steps that did not run (never reached, or left Running by a finished run): gray, not clickable */
.rv [id^="viewerplumbarea"] > [data-rv-off="1"] { --node: var(--rv-none); --rs: var(--rv-none); cursor: default !important; }
.rv [id^="viewerplumbarea"] > [data-rv-off="1"] * { cursor: default !important; }
.rv [id^="viewerplumbarea"] > .jtk-managed[data-rv-off="1"] > [id^="sftwoin"] {
    background: var(--rv-off-bg) !important;
    border: 2px dashed var(--rv-none) !important;
    box-shadow: none !important; animation: none !important;
}
.rv [id^="viewerplumbarea"] > .jtk-managed:not(.stfwstart)[data-rv-off="1"] > [id^="sftwoin"]::after { display: none; }
.rv [id^="viewerplumbarea"] > [data-rv-off="1"] > [id^="stfwoimage"] { filter: grayscale(1); opacity: .45; }
.rv [id^="viewerplumbarea"] > [data-rv-off="1"] > [id^="stfwotitle"] { opacity: .55; }
.rv [id^="viewerplumbarea"] > .jtk-managed[data-rv-off="1"]:hover > [id^="sftwoin"] { box-shadow: none !important; }
/* a finished run animates nothing: steps the server left as Running keep a static frame */
.rv[data-rv-done="1"] [id^="viewerplumbarea"] > * > [id^="sftwoin"],
.rv[data-rv-done="1"] [id^="viewerplumbarea"] > * > [id^="sftwoin"]::after,
.rv[data-rv-done="1"] [id^="viewerplumbarea"] > .stfwstart > .stfwstartouter { animation: none !important; }
/* the "shadow" block and the centre are layout only */
.rv [id^="viewerplumbarea"] > .jtk-managed:not(.stfwstart) > [id^="sftwoout"],
.rv [id^="viewerplumbarea"] > .jtk-managed:not(.stfwstart) > [id^="stfwoout"],
.rv [id^="viewerplumbarea"] > .jtk-managed:not(.stfwstart) > [id^="stfwocenter"] { background: transparent !important; }
.rv [id^="viewerplumbarea"] > .jtk-managed:not(.stfwstart) > [id^="stfwotitle"] {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    padding: 8px 6px 14px;
    color: var(--rv-card-ink) !important;
}
.rv [id^="viewerplumbarea"] > .jtk-managed:not(.stfwstart) > [id^="stfwotitle"] > br { display: none; }
.rv [id^="viewerplumbarea"] > .jtk-managed:not(.stfwstart) [id^="stfwwotypetitle"] {
    font-size: 9.5px !important; font-weight: 800 !important; letter-spacing: .08em; color: var(--node) !important;
}
.rv [id^="viewerplumbarea"] > .jtk-managed:not(.stfwstart) [id^="stfwwonametitle"] {
    font-size: 11.5px !important; font-weight: 650 !important; line-height: 1.25; text-align: center;
    color: var(--rv-card-ink) !important;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.rv [id^="viewerplumbarea"] > .jtk-managed:not(.stfwstart) [id^="stfwonotif"] { opacity: .5; }

/* START: the out-port carries the run status */
.rv [id^="viewerplumbarea"] > .stfwstart > .stfwstartouter { background: var(--rs) !important; box-shadow: 0 6px 16px -6px color-mix(in srgb, var(--rs) 60%, transparent); }
.rv [id^="viewerplumbarea"] > .stfwstart[data-rs="none"] > .stfwstartouter { background: #067647 !important; }
.rv [id^="viewerplumbarea"] > .stfwstart[data-rs="run"] > .stfwstartouter,
.rv [id^="viewerplumbarea"] > .stfwstart[data-rs="wait"] > .stfwstartouter { animation: rv-pulse 1.2s ease-in-out infinite; }
.rv [id^="viewerplumbarea"] > .stfwstart > .stfwstartinner {
    background: var(--rv-card) !important;
    color: var(--rv-card-ink) !important;
    font-size: 11.5px; letter-spacing: .08em; font-weight: 800; cursor: pointer;
    display: flex; align-items: center; justify-content: center; padding: 0;
    inset: 6px; width: auto; height: auto;   /* even ring: em sizing shrank with the 11.5px font (see stfwDesigner.css) */
}

/* connectors */
.rv .rv-canvas svg.jtk-connector path { stroke-width: 2px; }
.rv .rv-canvas .jtk-endpoint circle { stroke: var(--rv-card); stroke-width: 2px; }


@keyframes rv-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
@keyframes rv-ring {
    0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--rs) 35%, transparent), 0 6px 16px -6px rgba(16, 24, 40, .18); }
    50%      { box-shadow: 0 0 0 6px color-mix(in srgb, var(--rs) 0%, transparent), 0 6px 16px -6px rgba(16, 24, 40, .18); }
}

/* ---------------------------------------------------------------- stage detail */
.rv-report {
    grid-template-columns: minmax(140px, 1.2fr) auto minmax(200px, 2.4fr) 64px 64px 64px !important;
    gap: 0 !important;
    padding: 0 !important;
    max-height: 30em;
    background: transparent !important;
    border: 1px solid var(--ob-line);
    border-radius: 12px;
    overflow: auto;
    font-size: 13.5px !important;
    color: var(--ob-ink);
}
.rv-report > div { background: transparent !important; padding: 12px 14px; min-width: 0; display: flex; align-items: center; }
.rv-report > .rv-rh {
    padding: 9px 14px; background: var(--ob-head) !important; border-bottom: 1px solid var(--ob-line);
    position: sticky; top: 0; z-index: 1;
}
.rv-report > .rv-rh strong { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ob-muted); }
.rv-report > .rv-rh:nth-child(n+4) { justify-content: center; }
.rv-report > .rv-rc { border-top: 1px solid var(--ob-line); }
.rv-report > .rv-rc:nth-child(-n+12) { border-top: 0; }
.rv-report > .rv-c0 { font-weight: 650; }
.rv-report > .rv-c1 { align-self: center; justify-self: start; margin: 0 14px; padding: 0 10px !important; }
.rv-report > .rv-c2 { white-space: pre-wrap; word-break: break-word; color: var(--ob-ink-2); line-height: 1.45; }
.rv-report > .rv-c3, .rv-report > .rv-c4, .rv-report > .rv-c5 { justify-content: center; }
.rv-report > [data-has] svg, .rv-report > [data-has] img {
    width: 34px !important; height: 34px !important; padding: 8px; box-sizing: border-box;
    border: 1px solid var(--ob-line); border-radius: 9px; background: var(--ob-surface, #fff);
}
.rv-report > [data-has="1"] svg, .rv-report > [data-has="1"] img { cursor: pointer; border-color: var(--ob-line-strong); }
.rv-report > [data-has="1"] svg:hover, .rv-report > [data-has="1"] img:hover { background: var(--ob-hover); border-color: var(--ob-brand); }
.rv-report > [data-has="1"] svg path { fill: var(--ob-brand) !important; }
.rv-report > [data-has="0"] svg, .rv-report > [data-has="0"] img { opacity: .35; border-style: dashed; }

/* ---------------------------------------------------------------- dark */
html[data-theme="dark"] .rv, html[data-theme="dark"] .rv-report, html[data-theme="dark"] .ldcv.rv-modal {
    --rv-ok: #47CD89;   --rv-ok-bg: rgba(18, 183, 106, .16);
    --rv-warn: orange; --rv-warn-bg: rgba(255, 165, 0, .18);
    --rv-err: #F97066;  --rv-err-bg: rgba(240, 68, 56, .18);
    --rv-run: #8FB2FF;  --rv-run-bg: rgba(79, 139, 255, .18);
    --rv-int: #C3C9E3;  --rv-int-bg: rgba(195, 201, 227, .12);
    --rv-off-bg: rgba(152, 162, 179, .10);
    --rv-unk: #BDB4FE;  --rv-unk-bg: rgba(155, 138, 251, .18);
    --rv-nodata: #A6EF67; --rv-nodata-bg: rgba(102, 198, 28, .16);
    --rv-none: #5A6596;
    --rv-canvas: #0B1026; --rv-dot: #232C55;
    --rv-card: #18204A; --rv-card-line: #2E3A70; --rv-card-ink: #E7EAF6;
}
html[data-theme="dark"] .rv [id^="viewerplumbarea"] > .stfwstart[data-rs="none"] > .stfwstartouter { background: #12B76A !important; }
html[data-theme="dark"] .rv .rv-canvas svg.jtk-connector path[stroke="#0d78bc"] { stroke: #6F98FF; }
html[data-theme="dark"] .rv .rv-canvas svg.jtk-connector path[fill="#0d78bc"] { fill: #6F98FF; }
html[data-theme="dark"] .rv-report > [data-has="1"] svg path { fill: #8FB2FF !important; }

/* dialog titles: the viewer colours them by status (inline named colour); same palette as the pills */
.ldcv.rv-modal [id$="title"][data-s] { color: var(--s) !important; }
