/* ═══════════════════════════════════════════════════════════════════
   Workflow Builder — Embedded Runner Panel (phone emulator)
   ═══════════════════════════════════════════════════════════════════ */

/* ── Canvas push-right when runner panel is open ───────────────────── */

.canvas-main-area.has-runner {
    margin-right: 420px;
}

/* ── Runner panel shell (fixed, right edge) ─────────────────────────── */

.runner-panel {
    position: fixed;
    top: 3.5rem;
    right: 0;
    bottom: 0;
    width: 420px;
    z-index: 1030;
    background: var(--theme-background-subtle);
    border-left: 1px solid var(--theme-border);
    box-shadow: -2px 0 12px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: hidden;
}

/* ── Panel header ──────────────────────────────────────────────────── */

.runner-panel-header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0.75rem;
    border-bottom: 1px solid var(--theme-border);
    background: var(--theme-background-raised);
    flex-shrink: 0;
}

.runner-panel-title {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--theme-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.runner-panel-actions {
    display: flex;
    align-items: center;
    gap: 0.15rem;
}

.runner-panel-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: var(--theme-radius-sm, 4px);
    background: transparent;
    color: var(--theme-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 150ms ease, color 150ms ease;
    text-decoration: none;
    flex-shrink: 0;
}

.runner-panel-btn:hover {
    background: var(--theme-background-hover);
    color: var(--theme-text);
}

.runner-panel-btn.active {
    background: var(--theme-primary-muted);
    color: var(--theme-primary);
}

.runner-panel-btn.close {
    color: var(--theme-text-muted);
    margin-left: 0.25rem;
    border-left: 1px solid var(--theme-border);
    border-radius: 0 var(--theme-radius-sm, 4px) var(--theme-radius-sm, 4px) 0;
    width: 32px;
}

.runner-panel-btn.close:hover {
    background: var(--theme-danger-muted, rgba(220, 38, 38, 0.12));
    color: var(--theme-danger, #dc2626);
}

.runner-panel-lang {
    height: 28px;
    padding: 0 0.4rem;
    border: 1px solid var(--theme-border);
    border-radius: var(--theme-radius-sm, 4px);
    background: var(--theme-bg);
    color: var(--theme-text);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: lowercase;
    margin-right: 0.25rem;
    cursor: pointer;
}

.runner-panel-lang:hover {
    border-color: var(--theme-primary);
    color: var(--theme-primary);
}

/* ── Phone scroll container ─────────────────────────────────────────── */

.runner-phone-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem 0 0.75rem;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
    width: 100%;
}

/* ── Phone frame ──────────────────────────────────────────────────── */

.phone-frame {
    width: 375px;
    height: min(calc(100vh - 9rem), 720px);
    background: #1c1c1e;
    border-radius: 44px;
    box-shadow:
        0 0 0 1px #3a3a3c,
        0 0 0 3px #1c1c1e,
        0 16px 48px rgba(0, 0, 0, 0.45);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

/* Dynamic island notch */
.phone-notch {
    height: 36px;
    background: #1c1c1e;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 2px;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.phone-notch-pill {
    width: 126px;
    height: 34px;
    background: #000;
    border-radius: 0 0 20px 20px;
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
}

/* Screen — the run page fills it exactly; ONLY the step body scrolls, so the
   Next/Prev footer is always pinned visible regardless of content length. */
.phone-screen {
    flex: 1;
    min-height: 0;
    background: var(--theme-background);
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
}

.phone-screen .wf-run-page {
    flex: 1;
    height: auto;
    min-height: 0;
}

.phone-screen .wf-run-body {
    overflow-y: auto;
    min-height: 0;
}

/* The error branch has no body — let it grow so the footer stays pinned. */
.phone-screen .wf-run-error {
    flex: 1 1 auto;
}

/* Home indicator */
.phone-home-bar {
    height: 30px;
    background: #1c1c1e;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.phone-home-bar::after {
    content: '';
    width: 120px;
    height: 5px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

/* ── Standalone run host (/run/{id}) ───────────────────────────────── */

/* App-page fill: the host takes EXACTLY the visible area wf-main hands it
   (flex, never viewport math — 100vh lies about the shell header in popup
   windows, which shoved the runner footer below the fold). Only .wf-run-body
   scrolls; the frame always fits. */
.run-host {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    padding: 0.25rem 1rem 1.25rem;
    background:
        radial-gradient(1100px 520px at 50% -8%, rgba(var(--theme-primary-rgb), 0.07), transparent 60%),
        var(--theme-background-subtle);
}

.run-host-toolbar {
    width: 100%;
    max-width: 1100px;
    display: flex;
    justify-content: flex-end;
    gap: 0.25rem;
    padding: 0.3rem 0;
    flex-shrink: 0;
}

.run-host-stage {
    flex: 1;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: stretch;
    min-height: 0;
}

/* The standalone frame is LARGER than the builder panel's 375px emulator.
   Height comes from the flex chain (stage stretch), capped at phone height —
   the frame ALWAYS fits the window, at any size, resized live. */
.phone-frame.phone-frame-lg {
    width: 430px;
    height: auto;
    max-height: 932px;
    min-height: 0;
}

/* Widescreen mode — the SAME shell element (so the embedded runner never
   remounts on toggle), bezel chrome hidden, wide working card. */
.run-shell-wide {
    width: min(100%, 1100px);
    height: auto;
    max-height: 932px;
    min-height: 0;
    background: var(--theme-background);
    border: 1px solid var(--theme-border);
    border-radius: var(--theme-radius);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.16);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.run-shell-wide .phone-notch,
.run-shell-wide .phone-home-bar {
    display: none;
}

/* Embedded (iframe) containment — Launch Control's embed snippet. The run is a
   self-contained item on someone else's page: full-bleed, bezel-less at ANY
   size. Height rides the same flex chain — the iframe IS the viewport. */
.run-host.run-host-embedded {
    padding: 0;
    background: var(--theme-background);
}

.run-host-embedded .run-host-stage .phone-frame.phone-frame-lg,
.run-host-embedded .run-host-stage .run-shell-wide {
    width: 100%;
    max-height: none;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: var(--theme-background);
}

.run-host-embedded .run-host-stage .phone-notch,
.run-host-embedded .run-host-stage .phone-home-bar {
    display: none;
}

/* Phone-sized POPUP window: the window IS the phone — drop the bezel. NO
   viewport units here: 100vh ignored the shell header above wf-main, which
   pushed the frame (and the Next/Prev footer inside it) below the fold at
   EVERY window size. The flex chain fits the frame to the visible area. */
@media (max-width: 560px) {
    /* Full-bleed: drop wf-main's page padding around the runner (graceful in
       any browser without :has() support — a slim padded ring remains). */
    .wf-main:has(.run-host) {
        padding: 0;
    }

    .run-host {
        padding: 0;
        background: var(--theme-background);
    }

    .run-host-toolbar {
        display: none;
    }

    .run-host-stage .phone-frame.phone-frame-lg,
    .run-host-stage .run-shell-wide {
        width: 100%;
        max-height: none;
        border: none;
        border-radius: 0;
        box-shadow: none;
        background: var(--theme-background);
    }

    .run-host-stage .phone-frame .phone-notch,
    .run-host-stage .phone-frame .phone-home-bar {
        display: none;
    }
}

/* ── Dev mode info bar ─────────────────────────────────────────────── */

.runner-dev-bar {
    width: 375px;
    margin-top: 0.75rem;
    background: var(--theme-background-raised);
    border: 1px solid var(--theme-border);
    border-radius: var(--theme-radius);
    padding: 0.5rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    flex-shrink: 0;
}

.runner-dev-row {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    min-width: 0;
}

.runner-dev-label {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--theme-text-muted);
    flex-shrink: 0;
    width: 3.5rem;
}

.runner-dev-value {
    font-family: var(--theme-font-mono, ui-monospace, "Cascadia Code", monospace);
    font-size: 0.78rem;
    color: var(--theme-text);
    background: var(--theme-background-subtle);
    padding: 0.1rem 0.35rem;
    border-radius: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.runner-dev-value.path {
    color: var(--theme-primary);
    font-size: 0.72rem;
}

.runner-dev-empty {
    font-size: 0.75rem;
    color: var(--theme-text-muted);
    font-style: italic;
}

/* ── Canvas step highlight when runner is on that step ─────────────── */

.wf-step-card.runner-active {
    border-color: var(--theme-primary);
    background: var(--theme-primary-muted);
    box-shadow: 0 0 0 3px rgba(var(--theme-primary-rgb), 0.22);
    animation: runner-active-arrive 0.4s ease forwards;
}

.wf-step-card.runner-active .wf-step-name {
    color: var(--theme-primary);
    font-weight: 600;
}

@keyframes runner-active-arrive {
    0%   { box-shadow: 0 0 0 0   rgba(var(--theme-primary-rgb), 0.55); }
    55%  { box-shadow: 0 0 0 7px rgba(var(--theme-primary-rgb), 0.08); }
    100% { box-shadow: 0 0 0 3px rgba(var(--theme-primary-rgb), 0.22); }
}

/* ── Test Data Panel ────────────────────────────────────────────── */

.test-data-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: 0;
    overflow: hidden;
}

.test-data-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--theme-border);
    flex-shrink: 0;
}

.test-data-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--theme-text);
    letter-spacing: 0.02em;
}

.test-data-header-actions {
    display: flex;
    align-items: center;
    gap: 0.15rem;
}

.test-data-body {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-height: 0;
}

.test-data-section-label {
    font-size: 0.67rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--theme-text-muted);
    margin-bottom: 0.35rem;
}

.test-data-empty,
.test-data-instance-empty {
    font-size: 0.78rem;
    color: var(--theme-text-muted);
    font-style: italic;
    padding: 0.25rem 0;
}

.test-data-error {
    font-size: 0.78rem;
    color: var(--theme-danger, #dc2626);
    padding: 0.25rem 0;
}

/* ── Entity row ──────────────────────────────────────────────────── */

.test-data-entity {
    display: flex;
    flex-direction: column;
}

.test-data-entity-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    width: 100%;
    padding: 0.35rem 0.5rem;
    border: none;
    border-radius: var(--theme-radius-sm, 4px);
    background: transparent;
    color: var(--theme-text);
    font-size: 0.82rem;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: background 120ms ease;
}

.test-data-entity-btn:hover {
    background: var(--theme-background-hover);
}

.test-data-chevron {
    font-size: 0.65rem;
    color: var(--theme-text-muted);
    flex-shrink: 0;
}

.test-data-entity-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.test-data-badge {
    flex-shrink: 0;
    background: var(--theme-primary);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0.1rem 0.45rem;
    border-radius: 10px;
    line-height: 1.4;
}

/* ── Instance list ───────────────────────────────────────────────── */

.test-data-instance-list {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.2rem 0 0.4rem 1.4rem;
}

.test-data-instance {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    width: 100%;
    padding: 0.3rem 0.5rem;
    border: 1px solid transparent;
    border-radius: var(--theme-radius-sm, 4px);
    background: transparent;
    color: var(--theme-text);
    font-size: 0.78rem;
    text-align: left;
    cursor: pointer;
    transition: background 120ms ease, border-color 120ms ease;
}

.test-data-instance:hover {
    background: var(--theme-background-hover);
}

.test-data-instance.selected {
    background: var(--theme-primary-muted);
    border-color: var(--theme-primary-border, var(--theme-primary));
    color: var(--theme-primary);
}

.test-data-instance.selected i {
    color: var(--theme-primary);
}

.test-data-instance i {
    flex-shrink: 0;
    font-size: 0.82rem;
    color: var(--theme-text-muted);
}

.test-data-instance span {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Footer apply button ─────────────────────────────────────────── */

.test-data-footer {
    padding: 0.6rem 0.75rem;
    border-top: 1px solid var(--theme-border);
    flex-shrink: 0;
}

.test-data-apply-btn {
    width: 100%;
    padding: 0.45rem 0;
    border: none;
    border-radius: var(--theme-radius-sm, 4px);
    background: var(--theme-primary);
    color: #fff;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 150ms ease, opacity 150ms ease;
}

.test-data-apply-btn:hover:not(:disabled) {
    background: var(--theme-primary-hover, var(--theme-primary));
    filter: brightness(1.08);
}

.test-data-apply-btn:active:not(:disabled) {
    filter: brightness(0.95);
}

.test-data-apply-btn:disabled {
    opacity: 0.55;
    cursor: default;
}

/* ── Sample Context editor — fill available panel height ─────────── */

.sample-context-editor {
    flex: 1;
    min-height: 0;
    resize: none;
}

/* ── Context Inspector (DEBUG-only diagnostic) ────────────────────── */

.context-inspector-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: 0;
    overflow: hidden;
}

.context-inspector-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--theme-border);
    flex-shrink: 0;
}

.context-inspector-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--theme-text);
    letter-spacing: 0.02em;
}

.context-inspector-header-actions {
    display: flex;
    align-items: center;
    gap: 0.15rem;
}

.context-inspector-meta {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--theme-border);
    background: var(--theme-background-raised);
    font-size: 0.72rem;
    flex-shrink: 0;
}

.context-inspector-meta-row {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.1rem 0;
}

.context-inspector-meta-label {
    color: var(--theme-text-muted);
}

.context-inspector-meta-value {
    color: var(--theme-text);
    font-weight: 600;
}

.context-inspector-body {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0.75rem;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.context-inspector-section {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.context-inspector-section-label {
    font-size: 0.67rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--theme-text-muted);
}

.context-inspector-token-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.context-inspector-token-row input {
    flex: 1;
    min-width: 0;
}

.context-inspector-token-result {
    flex-shrink: 0;
    font-size: 0.78rem;
    color: var(--theme-text);
    max-width: 50%;
    word-break: break-word;
}

.context-inspector-token-unresolved {
    color: var(--theme-danger, #dc2626);
    font-style: italic;
}

.context-inspector-help {
    font-size: 0.7rem;
    color: var(--theme-text-muted);
    font-style: italic;
}

.context-inspector-empty {
    font-size: 0.78rem;
    color: var(--theme-text-muted);
    font-style: italic;
    padding: 0.25rem 0;
}

.context-inspector-json {
    margin: 0;
    font-size: 0.72rem;
    line-height: 1.4;
    color: var(--theme-text);
    white-space: pre-wrap;
    word-break: break-word;
}

/* ── THE CANVAS on the run host (Workflow.PresentationJson) ────────────── */
/* Background tokens override the host's default gradient (same-specificity
   pair with .run-host, combined selector wins). */
.run-host.wf-canvas-bg-subtle {
    background: var(--theme-background-subtle);
}

.run-host.wf-canvas-bg-primary {
    background: color-mix(in srgb, var(--theme-primary) 10%, var(--theme-background));
}

.run-host.wf-canvas-bg-transparent {
    background: transparent;
}

/* The wide shell fills its hero column instead of its own 1100px cap. */
.run-host-stage .wf-hero-content .run-shell-wide {
    width: 100%;
}

/* The hero image column caps at the same height as the content card so the
   two bottoms stay flush on tall monitors (the card caps at 932px). */
.run-host-stage .wf-hero-side {
    max-height: 932px;
}

/* An EMBED renders the hero like any other canvas — a WordPress-width iframe
   gets the full left/right split, and the responsive <=900px collapse hands a
   narrow iframe the hero TOP band instead. Full-bleed embeds cap nothing. */
.run-host-embedded .run-host-stage .wf-hero-side {
    max-height: none;
}

/* Phone-sized popup windows show the pure runner — a hero column would crowd
   a 430px phone window (the popup IS the phone; heroes are for wide canvases). */
@media (max-width: 560px) {
    .run-host:not(.run-host-embedded) .run-host-stage .wf-hero-side {
        display: none;
    }
}
