/*
 * Transfer Episode Tapestry — desktop clinical composition.
 *
 * This sheet is presentation-only and loads only when Loom AND Clinical
 * Canvas are effective. Every structural override is also marker-scoped so
 * removing data-tc-episode-tapestry restores the pre-existing stacked page.
 * The only other scope is data-tc-episode-fallback: a deliberately small
 * rescue that keeps canonical controls reachable if the Episode renderer
 * fails after the template has rendered.
 */

/* -------------------------------------------------------------------------
   Shared Episode language
   ------------------------------------------------------------------------- */

body.tc-page[data-tc-episode-tapestry="1"] .tc-capture-lede,
body.tc-page[data-tc-episode-tapestry="1"] .tc-captured-toggle {
    display: none;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-kicker {
    color: var(--term-gold);
    font-family: var(--term-font-mono);
    font-size: 0.58rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin,
body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now {
    min-width: 0;
    border: 1px solid var(--term-border-default);
    border-radius: 0.65rem;
    background:
        linear-gradient(135deg, var(--term-gold-ghost), transparent 42%),
        var(--term-bg-elevated);
    box-shadow:
        inset 0 1px 0 rgb(255 255 255 / 3%),
        0 0.55rem 1.6rem rgb(0 0 0 / 16%);
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin h2,
body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now h2 {
    margin: 0.1rem 0 0;
    color: var(--term-fg-primary);
    font-family: var(--term-font-display);
    font-size: 1rem;
    font-weight: 500;
    letter-spacing: 0.015em;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin__head {
    display: flex;
    grid-area: head;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

body.tc-page[data-tc-episode-tapestry="1"] #tcEpisodeOriginDetailsToggle {
    min-height: 2.25rem;
    padding: 0.4rem 0.72rem;
    border: 1px solid var(--term-gold-dim);
    border-radius: 999px;
    color: var(--term-gold);
    background: var(--term-gold-ghost);
    font-family: var(--term-font-mono);
    font-size: 0.62rem;
    letter-spacing: 0.04em;
    cursor: pointer;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin__summary {
    display: grid;
    grid-area: summary;
    grid-template-columns:
        minmax(16rem, 1.2fr)
        minmax(7rem, 0.45fr)
        minmax(13rem, 1fr);
    grid-template-areas:
        "patient call referrer"
        "reason clinical clinical";
    gap: 0.42rem 0.9rem;
    min-width: 0;
    min-height: 0;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin__patient {
    display: grid;
    grid-area: patient;
    grid-template-columns:
        minmax(7rem, 1fr)
        minmax(1.75rem, auto)
        minmax(1.75rem, auto)
        minmax(3.6rem, auto);
    gap: 0.25rem 0.45rem;
    min-width: 0;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin__call {
    grid-area: call;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin__referrer {
    grid-area: referrer;
    min-width: 0;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin__reason {
    grid-area: reason;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin__clinical-summary {
    grid-area: clinical;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin__item,
body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin__call {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 0.12rem;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin__label,
body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__label {
    color: var(--term-fg-muted);
    font-family: var(--term-font-mono);
    font-size: 0.55rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin__value {
    min-width: 0;
    overflow: hidden;
    color: var(--term-fg-primary);
    font-size: 0.76rem;
    line-height: 1.35;
    text-overflow: ellipsis;
    white-space: nowrap;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin__value.is-missing {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: var(--term-status-warning, #e69a4c);
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin__missing-icon {
    display: inline-grid;
    width: 1rem;
    height: 1rem;
    place-items: center;
    border: 1px solid currentColor;
    border-radius: 50%;
    font-family: var(--term-font-mono);
    font-size: 0.62rem;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin__source {
    display: flex;
    grid-area: source;
    align-items: center;
    justify-content: flex-end;
    gap: 0.45rem;
    color: var(--term-fg-secondary);
    font-family: var(--term-font-mono);
    font-size: 0.62rem;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin__source-icon {
    color: var(--term-live);
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin__source-edit {
    min-height: 2rem;
    padding: 0.28rem 0.58rem;
    border: 1px solid var(--term-border-strong);
    border-radius: 0.35rem;
    color: var(--term-fg-primary);
    background: var(--term-bg-input);
    font: inherit;
    cursor: pointer;
}

/* FIX (2026-07-29, doctor mid-shift: "the chart materials is now tiny tiny").
   The origin grid declares no grid-template-rows, so the `chart` area shares
   row 2 with `summary` and auto-sizes to whichever is taller. On a NEW transfer
   the summary is empty, the row collapses, and the paste target shrinks to
   nothing -- exactly inverted, because a new transfer is when a whole Epic dump
   gets pasted. Give the field its own floor so it can never be squeezed by an
   empty neighbour; it still grows when the summary is long. */
body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin #tcChartMaterialsField {
    grid-area: chart;
    min-width: 0;
    min-height: 14rem;
    max-width: none;
    margin: 0;
    overflow: hidden;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin #tcChartMaterials {
    box-sizing: border-box;
    min-height: 11rem;
    height: 100%;
    max-height: none;
    margin: 0;
    resize: vertical;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin #tcChartMaterialsView {
    box-sizing: border-box;
    min-height: 11rem;
    height: 100%;
    max-height: none;
    overflow-y: auto;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now > header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.55rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid var(--term-border-subtle);
}

body.tc-page[data-tc-episode-tapestry="1"] #tcEpisodeNowSummary {
    min-height: 0;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__status {
    margin: 0;
    padding: 0.7rem 0;
    color: var(--term-fg-secondary);
    font-size: 0.72rem;
    line-height: 1.45;
}

body.tc-page[data-tc-episode-tapestry="1"] [data-episode-now-state="listening"] .tc-episode-now__status,
body.tc-page[data-tc-episode-tapestry="1"] [data-episode-now-state="assembling"] .tc-episode-now__status {
    color: var(--term-live);
}

body.tc-page[data-tc-episode-tapestry="1"] [data-episode-now-state="starved"] .tc-episode-now__status {
    color: var(--term-status-warning, #e69a4c);
}

body.tc-page[data-tc-episode-tapestry="1"] [data-episode-now-state="settled"] > .tc-episode-now__status {
    display: none;
}

body.tc-page[data-tc-episode-tapestry="1"] [data-episode-now-live-projection="updating"] > .tc-episode-now__status {
    display: block;
    color: var(--term-live);
}

body.tc-page[data-tc-episode-tapestry="1"] [data-episode-now-live-projection="degraded"] > .tc-episode-now__status {
    display: block;
    color: var(--term-status-warning, #e69a4c);
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__content {
    display: grid;
    gap: 0.75rem;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__loom {
    position: sticky;
    z-index: 3;
    top: 0;
    display: grid;
    gap: 0.32rem;
    padding: 0.42rem;
    overflow: hidden;
    border: 1px solid var(--term-border-default);
    border-radius: 0.48rem;
    background:
        linear-gradient(90deg, transparent 0 12%, var(--term-live-ghost) 50%, transparent 88%),
        var(--term-bg-input);
    box-shadow: 0 0.42rem 0.9rem rgb(0 0 0 / 26%);
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__loom::after {
    position: absolute;
    right: 0.58rem;
    bottom: 0.34rem;
    left: 0.58rem;
    height: 1px;
    background: linear-gradient(
        90deg,
        transparent,
        var(--term-live-dim) 18% 82%,
        transparent
    );
    content: "";
    pointer-events: none;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__loom-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__loom-counts {
    color: var(--term-fg-muted);
    font-family: var(--term-font-mono);
    font-size: 0.52rem;
    letter-spacing: 0.025em;
    white-space: nowrap;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__strands {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.3rem;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__strand {
    --tc-strand-color: var(--term-fg-muted);

    position: relative;
    display: grid;
    align-content: space-between;
    gap: 0.3rem;
    min-width: 0;
    min-height: 2.5rem;
    padding: 0.3rem 0.3rem 0.26rem;
    border: 1px solid var(--term-border-subtle);
    border-top: 2px solid var(--tc-strand-color);
    border-radius: 0.32rem;
    background: rgb(0 0 0 / 10%);
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__strand[data-strand-status="processing"],
body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__strand[data-strand-status="retry_wait"] {
    --tc-strand-color: var(--term-live);

    background: var(--term-live-subtle);
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__strand[data-strand-status="applied"] {
    --tc-strand-color: var(--term-live);
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__strand[data-strand-status="empty"] {
    --tc-strand-color: var(--term-gold-dim);
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__strand[data-strand-status="failed"] {
    --tc-strand-color: var(--term-status-warning, #e69a4c);

    background: color-mix(
        in srgb,
        var(--term-status-warning, #e69a4c) 8%,
        var(--term-bg-input)
    );
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__strand-label {
    overflow: hidden;
    color: var(--term-fg-secondary);
    font-size: 0.54rem;
    font-weight: 650;
    line-height: 1.15;
    text-overflow: ellipsis;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__strand-status {
    color: var(--tc-strand-color);
    font-family: var(--term-font-mono);
    font-size: 0.46rem;
    font-weight: 700;
    letter-spacing: 0.045em;
    line-height: 1.15;
    text-transform: uppercase;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__strand[data-strand-status="processing"]::after,
body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__strand[data-strand-status="retry_wait"]::after {
    position: absolute;
    right: 0.34rem;
    bottom: 0.32rem;
    width: 0.28rem;
    height: 0.28rem;
    border-radius: 50%;
    background: var(--term-live);
    box-shadow: 0 0 0.52rem var(--term-live);
    content: "";
    animation: tc-episode-strand-pulse 1.4s ease-in-out infinite;
}

@keyframes tc-episode-strand-pulse {
    0%,
    100% {
        opacity: 0.35;
        transform: scale(0.75);
    }
    50% {
        opacity: 1;
        transform: scale(1);
    }
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__retry {
    min-height: 2rem;
    padding: 0.35rem 0.58rem;
    border: 1px solid var(--term-status-warning, #e69a4c);
    border-radius: 0.35rem;
    color: var(--term-status-warning, #e69a4c);
    background: transparent;
    font-family: var(--term-font-mono);
    font-size: 0.58rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    cursor: pointer;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__retry:disabled {
    opacity: 0.55;
    cursor: wait;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__headline,
body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__movement,
body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__unresolved {
    display: grid;
    gap: 0.32rem;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__fact {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.48rem;
    width: 100%;
    min-height: 2.55rem;
    padding: 0.5rem 0.58rem;
    border: 1px solid var(--term-border-default);
    border-left: 3px solid var(--term-live);
    border-radius: 0.35rem;
    color: var(--term-fg-primary);
    background: var(--term-bg-input);
    font-family: var(--term-font-body);
    font-size: 0.76rem;
    line-height: 1.4;
    text-align: left;
    cursor: pointer;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__fact-text {
    min-width: 0;
}

body.tc-page[data-tc-episode-tapestry="1"] [data-episode-now-live-projection-enabled="1"] .tc-episode-now__fact {
    flex-wrap: wrap;
}

body.tc-page[data-tc-episode-tapestry="1"] [data-episode-now-live-projection-enabled="1"] .tc-episode-now__fact-text {
    flex: 1 1 10rem;
}

body.tc-page[data-tc-episode-tapestry="1"] [data-episode-now-live-projection-enabled="1"] .tc-episode-now__change {
    flex: 1 0 100%;
    color: var(--term-fg-muted);
    font-family: var(--term-font-mono);
    font-size: 0.54rem;
    line-height: 1.3;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__provenance {
    flex: 0 0 auto;
    padding: 0.12rem 0.28rem;
    border: 1px solid currentColor;
    border-radius: 999px;
    color: var(--term-fg-muted);
    font-family: var(--term-font-mono);
    font-size: 0.47rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    line-height: 1.2;
    text-transform: uppercase;
    white-space: nowrap;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__provenance.is-current_call {
    color: var(--term-live);
    background: var(--term-live-subtle);
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__provenance.is-chart {
    color: var(--term-gold);
    background: var(--term-gold-ghost);
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__provenance.is-earlier_call {
    border-style: dashed;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__fact--movement {
    border-left-color: var(--term-gold);
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__fact--unresolved {
    border-left-color: var(--term-status-warning, #e69a4c);
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__fact[aria-pressed="true"] {
    border-color: var(--term-live);
    background: var(--term-live-subtle);
    box-shadow: inset 0 0 0 1px var(--term-live-dim);
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__unresolved-list {
    display: grid;
    gap: 0.38rem;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__clarification {
    display: block;
    padding: 0.48rem 0.58rem;
    border: 1px dashed var(--term-border-strong);
    border-radius: 0.35rem;
    color: var(--term-fg-secondary);
    font-size: 0.72rem;
    line-height: 1.4;
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__meta {
    margin: 0.1rem 0 0;
    color: var(--term-fg-muted);
    font-family: var(--term-font-mono);
    font-size: 0.56rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

body.tc-page[data-tc-episode-tapestry="1"] #tcEpisodeOriginDetailsToggle:focus-visible,
body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin__source-edit:focus-visible,
body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__fact:focus-visible,
body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__retry:focus-visible,
body.tc-page[data-tc-episode-tapestry="1"] .tc-clinical-canvas__switcher button:focus-visible {
    outline: 2px solid var(--term-live);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__strand::after {
        animation: none;
    }
}

body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now:focus-within,
body.tc-page[data-tc-episode-tapestry="1"] .tc-clinical-canvas__transcript-pane:focus-within,
body.tc-page[data-tc-episode-tapestry="1"] .tc-clinical-canvas__story-pane:focus-within {
    box-shadow: inset 0 0 0 2px var(--term-live-dim);
}

/* The legacy live layout hides form children with a high-specificity
   !important child sweep. Match that ownership edge with canonical IDs so
   these restores win by specificity at every width, not merely by load order. */
body.tc-page[data-tc-episode-tapestry="1"].tc-clinical-live .tc-list-panel {
    display: block !important;
}

body.tc-page[data-tc-episode-tapestry="1"].tc-clinical-live #tcWorkspaceForm > .tc-episode-origin {
    display: grid !important;
}

body.tc-page[data-tc-episode-tapestry="1"].tc-clinical-live #tcWorkspaceForm > .tc-episode-now {
    display: block !important;
}

body.tc-page[data-tc-episode-tapestry="1"].tc-clinical-live #tcWorkspaceForm > .tc-decision-spine {
    display: block !important;
}

body.tc-page[data-tc-episode-tapestry="1"].tc-clinical-live #tcWorkspaceForm > .tc-workspace-footer {
    display: flex !important;
}

body.tc-page[data-tc-episode-tapestry="1"].tc-clinical-live #tcRecorderPanel > .tc-recorder-controls {
    display: flex !important;
}

body.tc-page[data-tc-episode-tapestry="1"].tc-clinical-live #tcRecorderPanel > .tc-clinical-canvas {
    display: grid !important;
}

/* -------------------------------------------------------------------------
   Desktop Episode: literal Origin above one clinical stage + NOW/Decision
   ------------------------------------------------------------------------- */

@media (min-width: 1200px) {
    body.tc-page[data-tc-episode-tapestry="1"] {
        grid-template-columns: clamp(20rem, 25vw, 22.5rem) minmax(0, 1fr);
        grid-template-rows: auto minmax(0, 1fr);
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-list-panel {
        min-width: 0;
        overflow-y: auto;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-workspace {
        grid-column: 2;
        box-sizing: border-box;
        min-width: 0;
        min-height: 0;
        height: 100%;
        padding: 0.65rem 0.75rem 0.75rem;
        overflow: hidden;
    }

    body.tc-page[data-tc-episode-tapestry="1"] #tcWorkspaceForm {
        position: relative;
        display: grid;
        grid-template-columns: minmax(40rem, 1fr) clamp(18rem, 23vw, 22rem);
        grid-template-rows:
            auto
            clamp(9rem, 18vh, 10rem)
            minmax(7.5rem, 1fr)
            clamp(10rem, 20vh, 11.5rem)
            auto;
        gap: 0.55rem 0.65rem;
        min-width: 0;
        min-height: 0;
        height: 100%;
        overflow: hidden;
    }

    body.tc-page[data-tc-episode-tapestry="1"] #tcWorkspaceForm[hidden] {
        display: none;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-save-status {
        position: absolute;
        z-index: 4;
        top: 0.18rem;
        right: 0.45rem;
        max-width: 14rem;
        margin: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        pointer-events: none;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-topbar {
        grid-column: 1 / -1;
        grid-row: 1;
        min-width: 0;
        min-height: 2.65rem;
        margin: 0;
        padding: 0.18rem 15rem 0.38rem 0.45rem;
        border: 0;
        border-bottom: 1px solid var(--term-border-default);
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin {
        display: grid;
        grid-column: 1 / -1;
        grid-row: 2;
        grid-template-columns: minmax(0, 1fr) minmax(17rem, 0.34fr);
        grid-template-areas:
            "head source"
            "summary chart";
        /* Row 2 must clear the chart floor; auto alone collapses it on a new
           transfer where the summary column is still empty. */
        grid-template-rows: auto minmax(14rem, auto);
        gap: 0.42rem 0.9rem;
        box-sizing: border-box;
        min-height: 0;
        max-height: none;
        padding: 0.65rem 0.75rem;
        overflow: hidden;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-bottom-panel {
        grid-column: 1;
        grid-row: 3 / 6;
        min-height: 0;
        margin: 0;
        overflow: hidden;
        border: 0;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-bottom-panel > .tc-section,
    body.tc-page[data-tc-episode-tapestry="1"] .tc-bottom-panel .tc-section-body {
        min-height: 0;
        height: 100%;
        margin: 0;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-recorder {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto minmax(0, 1fr);
        min-width: 0;
        min-height: 0;
        height: 100%;
        margin: 0;
        padding: 0.58rem;
        overflow: hidden;
    }

    /*
     * Split projection intentionally does not manufacture clinical facts
     * during a call. Keep the canonical structured-field roll-up visible as
     * the immediate capture pulse until the evidence-bound post-call strands
     * populate NOW. This is the existing call-recorder authority, not a second
     * clinical projection.
     */
    body.tc-page[data-tc-episode-tapestry="1"].tc-clinical-live #tcRecorderPanel,
    body.tc-page[data-tc-episode-tapestry="1"]
        #tcRecorderPanel:has(
            > #tcClinicalCanvas[data-story-phase="assembling"]
            + #tcLiveIntake[data-capture-phase="complete"]
        ) {
        grid-template-rows: auto minmax(0, 1fr) auto;
    }

    body.tc-page[data-tc-episode-tapestry="1"].tc-clinical-live
        #tcRecorderPanel > #tcLiveIntake,
    body.tc-page[data-tc-episode-tapestry="1"]
        #tcClinicalCanvas[data-story-phase="assembling"]
        + #tcLiveIntake[data-capture-phase="complete"] {
        display: grid !important;
        grid-column: 1;
        grid-row: 3;
        grid-template-columns: minmax(11rem, 0.65fr) minmax(0, 1.35fr);
        grid-template-areas:
            "capture-head capture-detail"
            "capture-bar capture-bar";
        min-width: 0;
        margin: 0.45rem 0 0;
        border-color: var(--tc-arc-line-strong);
        border-radius: 0.6rem;
        background: var(--tc-arc-deep);
        box-shadow: inset 0 1px 0 rgb(255 255 255 / 3%);
    }

    body.tc-page[data-tc-episode-tapestry="1"].tc-clinical-live
        #tcLiveIntake > .tc-live-intake-header,
    body.tc-page[data-tc-episode-tapestry="1"]
        #tcClinicalCanvas[data-story-phase="assembling"]
        + #tcLiveIntake[data-capture-phase="complete"]
        > .tc-live-intake-header {
        grid-area: capture-head;
        min-width: 0;
        padding: 0.42rem 0.65rem;
        border-right: 1px solid var(--tc-arc-line);
        border-bottom: 0;
        background: var(--tc-arc-surface);
        box-shadow: none;
    }

    body.tc-page[data-tc-episode-tapestry="1"].tc-clinical-live
        #tcLiveIntake .tc-live-intake-kicker {
        color: var(--tc-arc-live);
    }

    body.tc-page[data-tc-episode-tapestry="1"]
        #tcClinicalCanvas[data-story-phase="assembling"]
        + #tcLiveIntake[data-capture-phase="complete"]
        .tc-live-intake-kicker {
        color: var(--term-gold);
    }

    body.tc-page[data-tc-episode-tapestry="1"].tc-clinical-live
        #tcLiveIntake .tc-live-intake-title,
    body.tc-page[data-tc-episode-tapestry="1"]
        #tcClinicalCanvas[data-story-phase="assembling"]
        + #tcLiveIntake[data-capture-phase="complete"]
        .tc-live-intake-title {
        display: none;
    }

    body.tc-page[data-tc-episode-tapestry="1"].tc-clinical-live
        #tcLiveIntake > .tc-live-intake-footer,
    body.tc-page[data-tc-episode-tapestry="1"]
        #tcClinicalCanvas[data-story-phase="assembling"]
        + #tcLiveIntake[data-capture-phase="complete"]
        > .tc-live-intake-footer {
        grid-area: capture-detail;
        grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
        min-width: 0;
        gap: 0.55rem;
        padding: 0.42rem 0.65rem;
        border-top: 0;
        background: transparent;
    }

    body.tc-page[data-tc-episode-tapestry="1"].tc-clinical-live
        #tcLiveIntake > #tcCaptureBar,
    body.tc-page[data-tc-episode-tapestry="1"]
        #tcClinicalCanvas[data-story-phase="assembling"]
        + #tcLiveIntake[data-capture-phase="complete"]
        > #tcCaptureBar {
        grid-area: capture-bar;
        height: 0.32rem;
        margin: 0 0.65rem 0.42rem;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-recorder--split > * {
        grid-column: 1;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-recorder-controls {
        display: flex;
        z-index: 5;
        grid-column: 1;
        grid-row: 1;
        min-width: 0;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-recorder > .tc-clinical-canvas {
        display: grid;
        grid-column: 1;
        grid-row: 2;
        min-width: 0;
        min-height: 0;
        height: auto;
        margin-top: 0.5rem;
        align-self: stretch;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-clinical-canvas {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto auto minmax(0, 1fr) auto;
        grid-template-areas: "switcher" "bedside" "stage" "agenda";
        min-width: 0;
        min-height: 0;
        height: 100%;
        overflow: hidden;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-clinical-canvas__switcher {
        display: grid;
        z-index: 3;
        grid-area: switcher;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.2rem;
        padding: 0.28rem;
        border-bottom: 1px solid var(--tc-arc-line);
        background: var(--tc-arc-deep);
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-clinical-canvas__switcher button {
        min-height: 2.25rem;
        border: 0;
        border-radius: 0.4rem;
        color: var(--tc-arc-muted);
        background: transparent;
        font: inherit;
        font-size: 0.72rem;
        font-weight: 700;
        cursor: pointer;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-clinical-canvas__switcher button[aria-pressed="true"] {
        color: var(--tc-arc-text);
        background: var(--tc-arc-surface-soft);
        box-shadow: inset 0 -2px 0 var(--tc-arc-live);
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-clinical-canvas__bedside {
        grid-area: bedside;
        min-width: 0;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-clinical-canvas__agenda {
        grid-area: agenda;
        min-width: 0;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-clinical-canvas__transcript-pane,
    body.tc-page[data-tc-episode-tapestry="1"] .tc-clinical-canvas__story-pane {
        grid-area: stage;
        min-width: 0;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
        border-right: 0;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-clinical-canvas[data-clinical-view="transcript"] .tc-clinical-canvas__story-pane,
    body.tc-page[data-tc-episode-tapestry="1"] .tc-clinical-canvas[data-clinical-view="story"] .tc-clinical-canvas__transcript-pane {
        display: none;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now {
        grid-column: 2;
        grid-row: 3;
        box-sizing: border-box;
        min-height: 0;
        padding: 0.75rem;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-decision-spine {
        grid-column: 2;
        grid-row: 4;
        box-sizing: border-box;
        min-width: 0;
        min-height: 0;
        max-height: none;
        margin: 0;
        padding: 0.62rem;
        overflow-y: auto;
        border: 1px solid var(--term-gold-dim);
        border-radius: 0.65rem;
        background: var(--term-bg-elevated);
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-decision-buttons {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.35rem;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-decision-btn {
        min-width: 0;
        min-height: 2.7rem;
        padding: 0.38rem 0.52rem;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-accept-block {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: 0.45rem;
        margin-top: 0.5rem;
        padding: 0.52rem;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-accept-unit,
    body.tc-page[data-tc-episode-tapestry="1"] .tc-accept-routing {
        min-width: 0;
        flex-wrap: wrap;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-accept-unit .tc-bed-chips {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        width: 100%;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-accept-routing .tc-select {
        width: min(100%, 10.5rem);
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-workspace-footer {
        display: flex;
        grid-column: 2;
        grid-row: 5;
        align-items: center;
        box-sizing: border-box;
        min-width: 0;
        margin: 0;
        padding: 0.52rem 0;
        border-top: 1px solid var(--term-border-default);
        background: transparent;
        box-shadow: none;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-workspace-footer .tc-generate-btn {
        width: 100%;
        min-width: 0;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-columns,
    body.tc-page[data-tc-episode-tapestry="1"] .tc-decision-detail {
        display: none;
    }

    body.tc-page[data-tc-episode-tapestry="1"]:not(.tc-working-notes-open) #tcWorkspaceForm[data-origin-details="open"] .tc-columns {
        display: grid;
        z-index: 20;
        grid-column: 1 / -1;
        grid-row: 3;
        min-height: 0;
        margin: 0;
        padding: 0.85rem;
        overflow-y: auto;
        border: 1px solid var(--term-boundary);
        border-radius: 0.65rem;
        background: var(--term-bg-surface);
    }

    body.tc-page[data-tc-episode-tapestry="1"]:not(.tc-working-notes-open) #tcWorkspaceForm[data-origin-details="open"] .tc-decision-detail {
        display: grid;
        z-index: 20;
        grid-column: 1 / -1;
        grid-row: 4;
        min-height: 0;
        max-height: 12rem;
        margin: 0;
        padding: 0.65rem 0.85rem;
        overflow-y: auto;
        border: 1px solid var(--term-boundary);
        border-radius: 0.65rem;
        background: var(--term-bg-surface);
    }

    body.tc-page[data-tc-episode-tapestry="1"]:not(.tc-working-notes-open) #tcWorkspaceForm[data-origin-details="open"] .tc-bottom-panel,
    body.tc-page[data-tc-episode-tapestry="1"]:not(.tc-working-notes-open) #tcWorkspaceForm[data-origin-details="open"] .tc-episode-now,
    body.tc-page[data-tc-episode-tapestry="1"]:not(.tc-working-notes-open) #tcWorkspaceForm[data-origin-details="open"] .tc-decision-spine {
        visibility: hidden;
        pointer-events: none;
    }

    body.tc-page[data-tc-episode-tapestry="1"].tc-clinical-live .tc-workspace-form > .tc-topbar,
    body.tc-page[data-tc-episode-tapestry="1"].tc-clinical-live .tc-workspace-form > .tc-bottom-panel {
        display: flex !important;
    }

    body.tc-page[data-tc-episode-tapestry="1"].tc-note-open {
        grid-template-columns: 0 minmax(0, 1fr);
    }

    body.tc-page[data-tc-episode-tapestry="1"].tc-note-open .tc-list-panel {
        visibility: hidden;
        pointer-events: none;
    }

    body.tc-page[data-tc-episode-tapestry="1"].tc-note-open .tc-workspace {
        margin-right: var(--tc-note-drawer-w, 480px);
    }

    body.tc-page[data-tc-episode-tapestry="1"].tc-note-open #tcWorkspaceForm {
        grid-template-columns: minmax(26rem, 1fr) minmax(17rem, 20rem);
    }
}

/* The desktop contract begins at 1200px, but the exact 40rem + NOW minimum
   cannot fit beside a 320px queue until 1280px. Compress only this 80px seam;
   controls remain present and the stacked fallback still begins below 1200. */
@media (min-width: 1200px) and (max-width: 1279.98px) {
    body.tc-page[data-tc-episode-tapestry="1"] #tcWorkspaceForm {
        grid-template-columns: minmax(33rem, 1fr) minmax(17rem, 18rem);
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin__summary {
        grid-template-columns:
            minmax(14rem, 1fr)
            minmax(6rem, 0.45fr)
            minmax(11rem, 0.9fr);
    }
}

/* -------------------------------------------------------------------------
   Sub-desktop functional stack. Tablet polish is deliberately out of scope;
   reachability and readable single-column flow are not.
   ------------------------------------------------------------------------- */

@media (max-width: 1199.98px) {
    body.tc-page[data-tc-episode-tapestry="1"] {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto auto auto;
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-header {
        grid-column: 1;
        grid-row: 1;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-list-panel {
        display: block !important;
        grid-column: 1;
        grid-row: 2;
        max-height: 20rem;
        overflow-y: auto;
        visibility: visible;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-workspace {
        grid-column: 1;
        grid-row: 3;
        min-width: 0;
        height: auto;
        padding: 0.75rem;
        overflow: visible;
    }

    body.tc-page[data-tc-episode-tapestry="1"] #tcWorkspaceForm {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto;
        min-width: 0;
        min-height: 0;
        height: auto;
        overflow: visible;
    }

    body.tc-page[data-tc-episode-tapestry="1"] #tcWorkspaceForm[hidden] {
        display: none;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-save-status,
    body.tc-page[data-tc-episode-tapestry="1"] .tc-topbar,
    body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin,
    body.tc-page[data-tc-episode-tapestry="1"] .tc-bottom-panel,
    body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now,
    body.tc-page[data-tc-episode-tapestry="1"] .tc-decision-spine,
    body.tc-page[data-tc-episode-tapestry="1"] .tc-workspace-footer {
        grid-column: 1;
        grid-row: auto;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas: "head" "summary" "source" "chart";
        max-height: none;
        margin-top: 0.55rem;
        padding: 0.75rem;
        overflow: visible;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin__summary {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-bottom-panel {
        min-height: 34rem;
        margin-top: 0.65rem;
        overflow: visible;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-recorder {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto minmax(30rem, 1fr);
        min-width: 0;
        min-height: 34rem;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-recorder > .tc-clinical-canvas {
        display: grid !important;
        grid-column: 1;
        grid-row: 2;
        min-height: 30rem;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now {
        display: block !important;
        max-height: none;
        margin-top: 0.65rem;
        padding: 0.75rem;
        overflow: visible;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-decision-spine {
        display: block !important;
        margin: 0.65rem 0 0;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-workspace-footer {
        display: flex !important;
        margin: 0.65rem 0 0;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-columns,
    body.tc-page[data-tc-episode-tapestry="1"] .tc-decision-detail {
        display: none;
    }

    body.tc-page[data-tc-episode-tapestry="1"] #tcWorkspaceForm[data-origin-details="open"] .tc-columns,
    body.tc-page[data-tc-episode-tapestry="1"] #tcWorkspaceForm[data-origin-details="open"] .tc-decision-detail {
        display: grid;
        grid-column: 1;
        grid-row: auto;
        max-height: none;
        overflow: visible;
    }

    body.tc-page[data-tc-episode-tapestry="1"].tc-note-open .tc-workspace {
        margin-right: 0;
    }
}

/* -------------------------------------------------------------------------
   Renderer failure: expose only the canonical stacked controls that the
   legacy live child-sweep hides. The base clinical canvas keeps layout.
   ------------------------------------------------------------------------- */

body[data-tc-episode-fallback="1"].tc-clinical-live #tcWorkspaceForm > .tc-episode-origin {
    display: block !important;
}

body[data-tc-episode-fallback="1"].tc-clinical-live #tcWorkspaceForm > .tc-episode-origin .tc-episode-origin__head,
body[data-tc-episode-fallback="1"].tc-clinical-live #tcWorkspaceForm > .tc-episode-origin .tc-episode-origin__summary,
body[data-tc-episode-fallback="1"].tc-clinical-live #tcWorkspaceForm > .tc-episode-origin .tc-episode-origin__source,
body[data-tc-episode-fallback="1"].tc-clinical-live #tcWorkspaceForm > .tc-episode-now {
    display: none !important;
}

body[data-tc-episode-fallback="1"].tc-clinical-live #tcChartMaterialsField,
body[data-tc-episode-fallback="1"].tc-clinical-live #tcWorkspaceForm > .tc-decision-spine,
body[data-tc-episode-fallback="1"].tc-clinical-live #tcWorkspaceForm > .tc-workspace-footer {
    display: block !important;
}

body[data-tc-episode-fallback="1"].tc-clinical-live #tcWorkspaceForm > .tc-workspace-footer {
    display: flex !important;
}

body[data-tc-episode-fallback="1"].tc-clinical-live #tcWorkspaceForm {
    height: auto;
    overflow-y: auto;
}

/* -------------------------------------------------------------------------
   Accessibility accommodations
   ------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    body.tc-page[data-tc-episode-tapestry="1"] * {
        scroll-behavior: auto;
    }
}

@media (forced-colors: active) {
    body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-origin,
    body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now {
        border-color: CanvasText;
    }

    body.tc-page[data-tc-episode-tapestry="1"] .tc-episode-now__fact,
    body.tc-page[data-tc-episode-tapestry="1"] #tcEpisodeOriginDetailsToggle {
        border-color: ButtonText;
    }
}

/* FIX (2026-07-29, doctor mid-shift): suppress the "Not supplied" wall on an
   UNTOUCHED transfer. Every field is empty by definition on a new referral, so
   a column of warning icons carries no information and buries the fields that
   do have content. Once anything has been captured the markers return, because
   there they are a real gap indicator. Data attribute is set by
   episode-origin.js::render from the model's `untouched` flag. */
body.tc-page[data-tc-episode-tapestry="1"]
  #tcWorkspaceForm[data-origin-untouched="1"] .tc-episode-origin__value.is-missing {
    visibility: hidden;
}
body.tc-page[data-tc-episode-tapestry="1"]
  #tcWorkspaceForm[data-origin-untouched="1"] .tc-episode-origin__source-icon {
    visibility: hidden;
}
