/* ── Experiments (MAG_SUP tier-3) + Daigrammar host ─────────────────────────
   Landing grid of experiment cards + the on-demand app host (daigrammar-plan §3.1). */

.experiments-view__intro {
    color: var(--text-secondary);
    font-size: var(--font-size-body-sm);
    margin: 0 0 var(--spacing-lg);
}

.experiment-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--spacing-md);
}

.experiment-card {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    text-align: left;
    padding: var(--spacing-lg);
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--border-radius-lg);
    cursor: pointer;
    transition: border-color 0.12s ease, transform 0.12s ease;
    font: inherit;
    color: inherit;
    /* Art support (below) needs a positioning context + rounded-corner clipping. Both are
       inert for cards with no art, so the default card is pixel-identical to before. */
    position: relative;
    overflow: hidden;
}
.experiment-card:hover {
    border-color: var(--border-strong);
    transform: translateY(-1px);
}

.experiment-card__title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: var(--font-size-body-lg);
    font-weight: 600;
    color: var(--text-primary);
}
/* ── optional card art: manifest `icon` + `background` ────────────────────────
   The icon is a plain <img> beside the title. The background rides a ::before so the
   scrim can sit above the image but below the content, and so the art never tints the
   border or the text. The scrim is built from --bg-elevated, so it tracks light/dark for
   free and text stays legible over art of any busyness. */
.experiment-card__name {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    min-width: 0;
}
.experiment-card__icon {
    width: 28px;
    height: 28px;
    flex: none;
    object-fit: contain;
    border-radius: var(--border-radius-sm);
}

.experiment-card--art::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(to bottom,
            color-mix(in srgb, var(--bg-elevated) 58%, transparent),
            var(--bg-elevated) 88%),
        var(--experiment-card-art);
    background-size: cover;
    background-position: center;
    pointer-events: none;
}
/* Lift the content above the art layer. */
.experiment-card--art > * {
    position: relative;
    z-index: 1;
}

.experiment-card__badge {
    font-size: var(--font-size-ui-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    background: var(--bg-subtle);
    border: 1px solid var(--border-subtle);
    border-radius: var(--border-radius-sm);
    padding: 2px 8px;
}
.experiment-card__blurb {
    margin: 0;
    color: var(--text-secondary);
    font-size: var(--font-size-body-sm);
    line-height: 1.45;
}
.experiment-card__open {
    color: var(--text-muted);
    font-size: var(--font-size-ui-sm);
    margin-top: auto;
}

/* On-demand app host (the tab container for a mounted experiment). Fills its parent
   (#main-content = flex:1 inside the 100vh .content-area, below the fixed header) rather than
   guessing a viewport offset — the old `calc(100vh - 200px)` left ~150px of dead space at the
   bottom (and would overflow if the chrome were taller). height:100% resolves against
   .main-content's definite (flex-allocated) height and adapts to any header/padding. */
.experiment-host {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 480px;
}
.experiment-host__bar {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding-bottom: var(--spacing-sm);
    margin-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--border-subtle);
    flex: 0 0 auto;
}
.experiment-host__back {
    background: none;
    border: none;
    color: var(--text-secondary);
    font: inherit;
    font-size: var(--font-size-ui-sm);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: var(--border-radius-sm);
}
.experiment-host__back:hover { color: var(--text-primary); background: var(--bg-subtle); }
.experiment-host__name {
    font-weight: 600;
    color: var(--text-primary);
}
.experiment-host__stage {
    flex: 1 1 auto;
    position: relative;
    border: 1px solid var(--border-default);
    border-radius: var(--border-radius-md);
    overflow: hidden;
}

/* ── ★ A SCROLLING STAGE, BY OPT-IN ONLY (day-1-followup item A) ─────────────
 *
 * `overflow: hidden` above is load-bearing for daigrammar: a canvas that scrolls is a canvas
 * whose pan gesture fights the page, so the stage must NOT scroll by default and this modifier
 * exists rather than a change to the shared rule.
 *
 * An experiment asks for it with `stageScroll: true` on its descriptor and the host puts the class
 * on the frame (js/components/experiments.js) — the same shape as `doc:` and `icon:`, one field and
 * no host edit per experiment.
 *
 * WHAT IT FIXES. An experiment that renders a LIST rather than a canvas was unusable in any window
 * short enough to matter, and it was three defects wearing one coat (reported by jmeyers driving
 * three browsers, 2026-08-28):
 *
 *   1. The stage clipped. A list taller than the stage simply ended, with no way to reach the rest.
 *   2. The list could not scroll within its own height, so "the height available to it" WAS the
 *      height it got — on the detail view, with three cards above the history, that is close enough
 *      to the table's own header to read as a collapsed list.
 *   3. ★ INFINITE SCROLL STOPPED AFTER ONE PAGE, and this is the one no eye would attribute to CSS.
 *      The sentinel is observed against the viewport; clipped inside a non-scrolling ancestor it
 *      can never intersect, and `#checkContinuation`'s rect test never comes back true either. So
 *      the list loaded page one and no scroll existed that could ask for page two. (Which is why
 *      "page a history longer than 50" could not be verified at all.)
 *
 * AND WHY THE HOST'S MIN-HEIGHT DROPS WITH IT. `min-height: 480px` is a floor for a CANVAS, which
 * has no natural size. A scrolling stage does not need one, and keeping it would buy TWO scrollbars
 * in a short window — the page scrolling to reveal a 480px host, and the stage scrolling inside it.
 * One scroll region is the whole point; 260px is a floor against degenerating to a sliver, not a
 * canvas allowance. */
.experiment-host--scroll {
    min-height: 260px;
}
.experiment-host--scroll .experiment-host__stage {
    overflow-y: auto;
    overflow-x: hidden;
    /* The list inside is the app's standard `.execution-list`, which brings no padding of its own
       because every other one sits inside `#main-content`'s. Nested in the stage it would sit flush
       against the border. */
    padding: var(--spacing-md);
}
/* ⚠ THE FIXED PAGINATION BAR CLEARS THE LAST ROW HERE TOO.
 *
 * `.pagination` is `position: fixed; bottom: 0` (components.css), and the app pays for that with
 * `padding-bottom: calc(var(--spacing-lg) + 36px)` on `.main-content` — the note in
 * inspector-ui-patterns.md §3 says so in as many words: it exists "to prevent the last table row
 * being hidden behind the fixed bar".
 *
 * Every list in MagGyver had been a top-level SECTION, whose `.pagination` sits directly inside
 * `#main-content`, so that one rule covered everything. An experiment's list is the first one
 * nested inside the stage, and the allowance does not reach it — the last row sits under the bar.
 *
 * Reported from real use of Baton's history list, 2026-08-27. Fixed HERE rather than in
 * `css/baton.css` because it names no experiment and every future one with a list has the same
 * problem; the same reason the `autoRefresh` host hook lives in the host (D12). Scoped to
 * `.execution-list` so an experiment that renders no list pays nothing.
 */
.experiment-host__stage .execution-list {
    padding-bottom: calc(var(--spacing-lg) + 36px);
}

/* Meeting-mode rig mount (M4). A SIBLING of the stage inside .experiment-host, so entering
   meeting mode is a move between siblings — no cross-container surgery, no index.html edit —
   and fullscreen composes for free, because .experiment-host is what the fullscreen toggle
   already targets.

   The rig's INSIDES are the meeting's (css/meeting.css); this is only the box it renders in and
   the rule that it costs nothing while nobody is meeting. `:empty` rather than a class the rig
   has to remember to toggle: a remembered step is exactly what the borrow/restore idiom exists
   to abolish. The consequence is that whatever renders here must not leave a stray text node. */
.experiment-host__rig {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.experiment-host__rig:empty { display: none; }

.experiment-host__error {
    padding: var(--spacing-lg);
    color: var(--color-log-error);
    font-size: var(--font-size-body-sm);
}

/* Generic host-bar action button (e.g. daigrammar's "Save as daigram"). */
.experiment-host__action {
    margin-left: auto;
    font: inherit;
    font-size: var(--font-size-ui-sm);
    cursor: pointer;
    padding: 4px 10px;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-default);
    background: var(--bg-elevated);
    color: var(--text-primary);
}
.experiment-host__action:hover { border-color: var(--border-strong); }

/* Right-aligned presence slot (multiplayer who's-here avatars). margin-left:auto pushes
   it — and any action buttons after it — to the right of the bar, even when empty. */
.experiment-host__presence {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 4px;
}
/* When avatars are present, actions sit just left/right of them with a normal gap rather
   than fighting over the auto-margin. */
.experiment-host__presence ~ .experiment-host__action { margin-left: var(--spacing-md); }

/* Inline-editable daigram title in the host bar (Track 2). */
.experiment-host__name--editable { cursor: text; border-radius: var(--border-radius-sm); padding: 2px 6px; }
.experiment-host__name--editable:hover { background: var(--bg-subtle); }
.experiment-host__title-input {
    font: inherit;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--bg-input, var(--bg-subtle));
    border: 1px solid var(--border-strong);
    border-radius: var(--border-radius-sm);
    padding: 1px 6px;
    min-width: 200px;
}

/* ── Daigram browser (the CRUD library) — Track 2 ──────────────────────────── */
.daigram-browser { padding: var(--spacing-md); height: 100%; overflow-y: auto; box-sizing: border-box; }
.daigram-browser__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-md);
}
.daigram-browser__title { margin: 0; font-size: var(--font-size-body-lg); color: var(--text-primary); }
.daigram-browser__new,
.daigram-browser__btn,
.daigram-row__btn {
    font: inherit;
    font-size: var(--font-size-ui-sm);
    cursor: pointer;
    padding: 6px 12px;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-default);
    background: var(--bg-elevated);
    color: var(--text-primary);
}
.daigram-browser__new:hover,
.daigram-browser__btn:hover,
.daigram-row__btn:hover { border-color: var(--border-strong); }
.daigram-row__btn--danger { color: var(--color-log-error); }
.daigram-row__btn--danger:hover { border-color: var(--color-log-error); }

.daigram-browser__new-input,
.daigram-row__edit {
    font: inherit;
    color: var(--text-primary);
    background: var(--bg-input, var(--bg-subtle));
    border: 1px solid var(--border-strong);
    border-radius: var(--border-radius-sm);
    padding: 6px 10px;
    width: 100%;
    box-sizing: border-box;
    margin-bottom: var(--spacing-sm);
}
.daigram-row__edit { margin-bottom: 0; width: auto; flex: 1 1 auto; }

.daigram-browser__status {
    font-size: var(--font-size-body-sm);
    color: var(--text-secondary);
    margin-bottom: var(--spacing-sm);
}
.daigram-browser__status[data-kind="error"] { color: var(--color-log-error); }

.daigram-browser__section { margin-bottom: var(--spacing-lg); }
.daigram-browser__section-title {
    margin: 0 0 var(--spacing-sm);
    font-size: var(--font-size-ui-sm);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}
.daigram-browser__empty,
.daigram-browser__loading { color: var(--text-muted); font-size: var(--font-size-body-sm); margin: 0; }
.daigram-browser__error {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    color: var(--color-log-error);
    font-size: var(--font-size-body-sm);
}

.daigram-row {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-sm) var(--spacing-md);
    border: 1px solid var(--border-subtle);
    border-radius: var(--border-radius-md);
    background: var(--bg-elevated);
    margin-bottom: 6px;
}
.daigram-row:hover { border-color: var(--border-default); }
.daigram-row__open {
    flex: 1 1 auto;
    text-align: left;
    font: inherit;
    font-size: var(--font-size-body-sm);
    color: var(--text-primary);
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px 0;
}
.daigram-row__open:hover { color: var(--accent, #5a8bff); }
.daigram-row__actions,
.daigram-row__confirm { display: flex; align-items: center; gap: var(--spacing-sm); flex: 0 0 auto; }
.daigram-row__confirm span { font-size: var(--font-size-body-sm); color: var(--text-secondary); }

/* ── P1 daigram thumbnails: card grid ─────────────────────────────────────── */
.daigram-browser__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--spacing-md);
}
.daigram-card {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-subtle);
    border-radius: var(--border-radius-md);
    background: var(--bg-elevated);
    /* No overflow:hidden — the kebab dropdown must escape the card. The thumbnail rounds its own
       top corners (below) so the card top still looks clipped. */
}
.daigram-card:hover { border-color: var(--border-default); }
.daigram-card__thumb {
    position: relative;
    aspect-ratio: 16 / 10;
    width: 100%;
    background: var(--bg-subtle);
    cursor: pointer;
    overflow: hidden;
    border-top-left-radius: var(--border-radius-md);
    border-top-right-radius: var(--border-radius-md);
}
.daigram-card__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.daigram-card__monogram {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.2rem;
    font-weight: 600;
    color: #fff;
    text-transform: uppercase;
    user-select: none;
}
.daigram-card__body {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
}
.daigram-card .daigram-row__open {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.daigram-card__menu-wrap { position: relative; flex: 0 0 auto; }
.daigram-card__menu-btn {
    font: inherit;
    font-size: var(--font-size-body-lg);
    line-height: 1;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: var(--border-radius-sm);
    border: 1px solid transparent;
    background: none;
    color: var(--text-secondary);
}
.daigram-card__menu-btn:hover { border-color: var(--border-default); color: var(--text-primary); }
.daigram-card__menu {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    z-index: 30;
    min-width: 140px;
    display: flex;
    flex-direction: column;
    padding: 4px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--border-radius-sm);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
}
.daigram-card__menu[hidden] { display: none; }
.daigram-card__menu .daigram-row__actions,
.daigram-card__menu .daigram-row__confirm {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    width: 100%;
}
.daigram-card__menu .daigram-row__btn { width: 100%; text-align: left; }
