/*
 * static/css/artifacts.css — display cards, stage pane / mobile sheet, viewer chrome, deck controls, lightbox. Artifact-only tokens live here; global tokens are requested from the tokens.css owner.
 *
 * Owner: WP B-15; restyled by the UI overhaul (plan R-106, batch 4 §9 phase 2; docs/plan/specs/ui-overhaul.md
 * §6.9–§6.10). Spec: FR §3, §4.1, §4.8, §6, §10 (the canvases --canvas-*, --checker-*, the stacking tokens
 * --z-stage, --z-lightbox come from tokens.css). Every selector is defined once, in one file (I7; T-CSS checks the
 * critical ones). No inline styles are written by the JS (CSP): sizes go through CSSOM custom properties / properties.
 *
 * The card's action keys whose whole text is a glyph (⧉ ⤓ ☰ ◐ ↗ ⛶ and the ⋯ menu) keep it in the DOM and draw a
 * line icon (brief §3.5); the copy result (✓ / ✕, the button's ::after) stays visible beside the icon. Every other
 * action shows its whole text ("PNG", "↻ Reload", "▸ Side viewer").
 */

/* Artifact-only values use var() fallbacks instead of a :root block of their own (tokens.css and its generated
 * companion icons.css own :root, I7; brief §7 step 2).
 * --aiw-stage-w is set on <html> by stage.js while the desktop pane is open. */

/* ---- the card (FR §3.1) ------------------------------------------------------------------ */
.aiw-card {
    --aiw-card-bar-h: 46px;
    container-type: inline-size;
    container-name: aiw-card;
    position: relative;
    margin: var(--space-1) 0;
    max-width: 100%;
    background: var(--c-surface);
    border: 1px solid var(--c-outline-variant);
    border-radius: var(--radius-lg);
    box-shadow: var(--elev-card);
    overflow: hidden;
}

/* the "made by AI" bar (FR §3.1): chrome always outside the iframe, a hairline under it, the kind in the accent */
.aiw-card__bar {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-height: var(--aiw-card-bar-h);
    padding: var(--space-1) 6px var(--space-1) 14px;
    background: var(--c-surface);
    box-shadow: inset 0 -1px 0 var(--c-outline-variant);
    font: var(--t-body-s);
}

/* the kind glyph (kept in the DOM, aria-hidden) drawn as a line icon in the accent */
.aiw-card__icon {
    flex: 0 0 auto;
    display: inline-flex;
    width: 18px;
    height: 18px;
    color: var(--c-accent);
    font-size: 0;
    line-height: 0;
}
.aiw-card__icon::before {
    content: ''; width: 18px; height: 18px; background: currentColor;
    -webkit-mask: var(--icon-file) center / contain no-repeat; mask: var(--icon-file) center / contain no-repeat;
}
.aiw-card:is([data-view="image"], [data-view="svg"]) .aiw-card__icon::before { -webkit-mask-image: var(--icon-image); mask-image: var(--icon-image); }
.aiw-card:is([data-view="html"], [data-view="notebook"]) .aiw-card__icon::before { -webkit-mask-image: var(--icon-code); mask-image: var(--icon-code); }
.aiw-card[data-view="deck"] .aiw-card__icon::before { -webkit-mask-image: var(--icon-slides); mask-image: var(--icon-slides); }
.aiw-card[data-view="sheet"] .aiw-card__icon::before { -webkit-mask-image: var(--icon-table); mask-image: var(--icon-table); }
.aiw-card:is([data-view="pdf"], [data-view="office"], [data-view="markdown"], [data-view="latex"], [data-view="text"]) .aiw-card__icon::before { -webkit-mask-image: var(--icon-file-text); mask-image: var(--icon-file-text); }
.aiw-card[data-view="media"] .aiw-card__icon::before { -webkit-mask-image: var(--icon-audio); mask-image: var(--icon-audio); }
.aiw-card[data-view="archive"] .aiw-card__icon::before { -webkit-mask-image: var(--icon-archive); mask-image: var(--icon-archive); }

.aiw-card__title {
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
    color: var(--c-on);
}

/* The meta is secondary: a 0 basis gives it only the room the title leaves, so it shrinks away
   before the title is cut (V-6 Y34). */
.aiw-card__meta {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--c-on-3);
}

.aiw-badge {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    height: 20px;
    padding: 0 8px;
    border-radius: var(--radius-pill);
    background: var(--c-accent-container);
    color: var(--c-on-accent-container);
    font: var(--t-label-s);
}

.aiw-badge[data-badge="deleted"] { background: var(--c-danger-container); color: var(--c-on-danger-container); }

.aiw-card__errors {
    flex: 0 0 auto;
    height: 22px;
    padding: 0 9px;
    border: 0;
    border-radius: var(--radius-pill);
    background: var(--c-warning-container);
    color: var(--c-on-warning-container);
    font: var(--t-label-s);
    cursor: pointer;
}

.aiw-card__errors-pop {
    position: absolute;
    top: 48px;
    right: var(--space-2);
    z-index: 3;
    max-width: min(420px, calc(100% - 16px));
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    background: var(--c-surface-raised);
    color: var(--c-on-2);
    font: var(--t-body-s);
    box-shadow: var(--elev-2);
}

.aiw-card__errors-item { overflow-wrap: anywhere; padding: 2px 0; }

.aiw-card__actions { display: inline-flex; flex: 0 0 auto; align-items: center; gap: 2px; margin-left: auto; }

/* the shared bar button: 32 px text buttons (card actions, the side viewer's header) */
.aiw-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 32px;
    height: 32px;
    padding: 0 10px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--c-on-2);
    font: var(--t-label-m);
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color var(--dur-1) var(--ease-standard), color var(--dur-1) var(--ease-standard);
}

.aiw-btn:hover { background: var(--c-hover); color: var(--c-on); }
.aiw-btn:active { background: var(--c-pressed); }
.aiw-btn[disabled] { opacity: 0.5; cursor: default; }
/* the copy result: its own text size, so it shows beside the copy icon (never hidden with the glyph) */
.aiw-btn[data-copy]::after { font: var(--t-label-m); font-size: 0.8125rem; line-height: 1; }
.aiw-btn[data-copy="ok"]::after { content: " ✓"; color: var(--c-accent-text); }
.aiw-btn[data-copy="fail"]::after { content: " ✕"; color: var(--c-danger); }

/* The glyph-only keys: 32 px icon buttons (the glyph stays the text) */
.aiw-card__actions > :is(.aiw-act-copy, .aiw-act-download, .aiw-act-outline, .aiw-act-background, .aiw-act-newtab, .aiw-act-fullscreen, .aiw-card__more) {
    width: 32px;
    padding: 0;
    font-size: 0;
}
.aiw-card__actions > .aiw-act-copy[data-copy] { width: auto; padding: 0 8px 0 7px; }
.aiw-card__actions > :is(.aiw-act-copy, .aiw-act-download, .aiw-act-outline, .aiw-act-background, .aiw-act-newtab, .aiw-act-fullscreen, .aiw-card__more)::before {
    content: ''; flex: none; width: 18px; height: 18px; background: currentColor;
    -webkit-mask: var(--icon-copy) center / contain no-repeat; mask: var(--icon-copy) center / contain no-repeat;
}
.aiw-card__actions > .aiw-act-download::before { -webkit-mask-image: var(--icon-download); mask-image: var(--icon-download); }
.aiw-card__actions > .aiw-act-outline::before { -webkit-mask-image: var(--icon-list); mask-image: var(--icon-list); }
.aiw-card__actions > .aiw-act-background::before { -webkit-mask-image: var(--icon-contrast); mask-image: var(--icon-contrast); }
.aiw-card__actions > .aiw-act-newtab::before { -webkit-mask-image: var(--icon-external); mask-image: var(--icon-external); }
.aiw-card__actions > .aiw-act-fullscreen::before { -webkit-mask-image: var(--icon-expand); mask-image: var(--icon-expand); }
.aiw-card__actions > .aiw-card__more::before { -webkit-mask-image: var(--icon-more); mask-image: var(--icon-more); }

.aiw-card__more { display: none; }

/* below 480 px of card width the actions collapse into the ⋯ menu (FR §10.3) */
@container aiw-card (max-width: 480px) {
    .aiw-card__actions > .aiw-btn { display: none; }
    .aiw-card__actions > .aiw-card__more { display: inline-flex; }
    .aiw-card__meta { display: none; }
}

@media (pointer: coarse) {
    .aiw-btn { min-width: 40px; height: 40px; }
    .aiw-card__actions > :is(.aiw-act-copy, .aiw-act-download, .aiw-act-outline, .aiw-act-background, .aiw-act-newtab, .aiw-act-fullscreen, .aiw-card__more) { width: 40px; }
    .aiw-card { --aiw-card-bar-h: 48px; }
}

/* ---- body, viewer box, canvas backgrounds ------------------------------------------------ */
.aiw-card__body {
    position: relative;
    width: 100%;
    overflow: hidden;
    background: var(--c-surface);
}

.aiw-card__body[data-bg="light"] { background: var(--canvas-light); }
.aiw-card__body[data-bg="dark"] { background: var(--canvas-dark); }
.aiw-card__body[data-bg="checker"],
.aiw-lightbox__img[data-bg="checker"] {
    background-color: var(--checker-b);
    background-image:
        linear-gradient(45deg, var(--checker-a) 25%, transparent 25%),
        linear-gradient(-45deg, var(--checker-a) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, var(--checker-a) 75%),
        linear-gradient(-45deg, transparent 75%, var(--checker-a) 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

/* A static SVG in <img> (svg-scheme.js, FR §10.2): a plain one draws light; one that follows the device (too
   large to pin) draws in the device's scheme in both engines; a dark-capable one is a copy pinned to the wanted
   scheme, and its system colours match. The canvas behind it is the card's, viewer's or lightbox's data-bg. */
img[data-svg-scheme="pending"],
img[data-svg-scheme="plain"],
img[data-svg-scheme="themed"][data-svg-draw="light"] { color-scheme: light; }
img[data-svg-scheme="themed"][data-svg-draw="dark"] { color-scheme: dark; }
img[data-svg-scheme="device"] { color-scheme: normal; }

.aiw-card__viewer { position: relative; width: 100%; }
.aiw-card[data-view="deck"] .aiw-card__viewer { position: absolute; inset: 0; }

.aiw-card__caption {
    padding: var(--space-2) 14px var(--space-3);
    border-top: 1px solid var(--c-outline-variant);
    color: var(--c-on-2);
    font: var(--t-body-s);
    line-height: 1.5;
}

/* a deck's speaker notes, linked under the slide frame (deck-notes.js, Ray 2026-10-30): open by default, the toggle
   collapses them to a thin bar. The open panel keeps one height whatever the slide's notes (long notes scroll
   inside), so moving through the deck never moves the slide (a chat pinned to the bottom follows every resize).
   Gate 3 (2026-10-31): the card fits the visible chat (--aiw-chat-view-h, chat.css) with its panel: the slide box
   narrows, still at the deck's aspect (--aiw-deck-ar, display-card.js), so header + slide + notes are on screen
   together; the panel is shorter on a narrow card (40cqw: the card is the container). */
.aiw-card[data-view="deck"] {
    --aiw-notes-body-h: clamp(80px, min(22vh, 40cqw), 168px);
    --aiw-notes-toggle-h: 36px;
}

.aiw-card[data-view="deck"][data-notes="closed"] {
    --aiw-deck-chrome: calc(var(--aiw-card-bar-h) + var(--aiw-notes-toggle-h) + 4px);
}

.aiw-card[data-view="deck"][data-notes="open"] {
    --aiw-deck-chrome: calc(var(--aiw-card-bar-h) + var(--aiw-notes-toggle-h) + var(--aiw-notes-body-h) + 4px);
}

.aiw-card[data-view="deck"][data-notes] > .aiw-card__body {
    width: min(100%, max(200px, calc((var(--aiw-chat-view-h, 100dvh) - var(--aiw-deck-chrome)) * var(--aiw-deck-ar, 1.7778))));
    margin-inline: auto;
}

/* the notes panel: the low surface under a hairline, no gold strip */
.aiw-card__notes {
    border-top: 1px solid var(--c-outline-variant);
    background: var(--c-surface-low);
    font: var(--t-body-m);
}

.aiw-card__notes-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    min-height: var(--aiw-notes-toggle-h, 36px);
    padding: 0 14px;
    border: 0;
    background: transparent;
    color: var(--c-on-2);
    font: var(--t-label-m);
    text-align: left;
    cursor: pointer;
    transition: color var(--dur-1) var(--ease-standard), background-color var(--dur-1) var(--ease-standard);
}

.aiw-card__notes-toggle:hover { color: var(--c-on); background: var(--c-hover); }
.aiw-card__notes-toggle:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--c-focus); }

/* ▾ / ▸ (CSS text) drawn as a line chevron in the accent */
.aiw-card__notes-chevron::before {
    content: "";
    display: inline-block;
    width: 16px;
    height: 16px;
    vertical-align: middle;
    background: var(--c-accent);
    -webkit-mask: var(--icon-chevron-down) center / contain no-repeat;
    mask: var(--icon-chevron-down) center / contain no-repeat;
    transition: transform var(--dur-2) var(--ease-standard);
}

.aiw-card__notes[data-closed="true"] .aiw-card__notes-chevron::before { transform: rotate(-90deg); }

.aiw-card__notes-body {
    height: var(--aiw-notes-body-h);
    overflow-y: auto;
    padding: 0 16px 14px;
    color: var(--c-on-2);
    line-height: 1.6;
    overflow-wrap: anywhere;
}

.aiw-card__notes-body:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--c-focus); }
.aiw-card__notes-body p { margin: 0 0 var(--space-2); }
.aiw-card__notes-body :is(ul, ol) { margin: 0 0 var(--space-2); padding-left: 1.4rem; }
.aiw-card__notes-body li { margin: 2px 0; }
.aiw-card__notes-body li::marker { color: var(--c-on-3); }
.aiw-card__notes-body blockquote { margin: 0 0 var(--space-2); padding-left: var(--space-3); border-left: 2px solid var(--c-outline-variant); }
.aiw-card__notes-body code { font-family: var(--font-mono); font-size: 0.875em; color: var(--c-on); }

.aiw-card__notes-body pre {
    margin: 0 0 var(--space-2);
    padding: var(--space-2);
    overflow-x: auto;
    background: var(--c-code);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 12px;
    white-space: pre-wrap;
}

.aiw-card__notes-body > :last-child,
.aiw-card__notes-body > div > :last-child { margin-bottom: 0; }
.aiw-card__notes-body > div + div { margin-top: var(--space-2); }
.aiw-card__notes-none { margin: 0; color: var(--c-on-3); font-style: italic; }
/* typeset math in the notes (Ray 2026-11-07, markdown.js typesetNotesMath): TeX source while KaTeX loads or on an
   error, a display formula on its own line scrolling sideways when wide */
.aiw-card__notes-body .aiw-math-pending { font-family: var(--font-mono); font-size: 0.875em; color: var(--c-on-3); }
.aiw-card__notes-body .aiw-math-error { font-family: var(--font-mono); font-size: 0.875em; color: var(--c-danger); }
.aiw-card__notes-body .aiw-math-display { display: block; overflow-x: auto; overflow-y: hidden; }
.aiw-card__notes-body .aiw-math-display .katex-display { margin: var(--space-1) 0; }

@media (pointer: coarse) {
    .aiw-card[data-view="deck"] { --aiw-notes-toggle-h: 40px; }
}

/* loading skeleton (FR §3.2); a static block under prefers-reduced-motion */
.aiw-card__skeleton {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    padding: var(--space-2) var(--space-3);
    background: linear-gradient(100deg, transparent 30%, var(--c-surface-high) 50%, transparent 70%);
    background-size: 200% 100%;
    animation: aiw-shimmer 1.4s linear infinite;
}

.aiw-card__loading-text { color: var(--c-on-3); font: var(--t-body-s); font-size: 0.75rem; }

@keyframes aiw-shimmer {
    from { background-position: 100% 0; }
    to { background-position: -100% 0; }
}

.aiw-card__error {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    min-height: 72px;
    padding: var(--space-3) 14px;
    color: var(--c-on-2);
    font: var(--t-body-s);
}

.aiw-card[data-error="deleted"] .aiw-card__error-text { color: var(--c-on-3); font-style: italic; }
.aiw-card:is([data-error="misbehaved"], [data-error="flooded"], [data-error="focus_theft"]) .aiw-card__error-text { color: var(--c-danger); }

.aiw-card__resume,
.aiw-card__staged {
    position: absolute;
    inset: 0;
    width: 100%;
    border: 0;
    background: transparent;
    color: var(--c-on-2);
    font: var(--t-body-s);
    cursor: pointer;
}

.aiw-card__resume:hover,
.aiw-card__staged:hover { color: var(--c-on); background: var(--c-hover); }
.aiw-card__resume:focus-visible,
.aiw-card__staged:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--c-focus); }

/* mobile "Tap to interact" shield over scrolling html frames (FR §4.8) */
.aiw-card__shield {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: var(--space-3);
    border: 0;
    background: transparent;
    font: inherit;
    font-size: 12px;
}

/* fixed colours: the html canvas is always white, whatever the theme (L10) */
.aiw-card__shield-label {
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.62);
    color: #fff;
    line-height: 1.4;
    pointer-events: none;
}

.aiw-card__shield::after {
    content: "";
    position: absolute;
    inset: 0;
}

/* ---- the sandboxed iframe (FR §4.1) -------------------------------------------------------- */
/* The frame's color-scheme is the app's light/dark setting, never the device's (FR §10.2): WebKit gives the
   page that preference (prefers-color-scheme), scheme@1.js does it in Chromium. */
.aiw-frame {
    display: block;
    width: 100%;
    border: 0;
    color-scheme: dark;
}

[data-theme="light"] .aiw-frame { color-scheme: light; }

/* html and interactive svg, never transparent (FR §4.1, §10.2): a page that supports the app's scheme shows
   on this canvas; one that does not (no color-scheme, black text) gets the engine's opaque white canvas */
.aiw-frame--canvas { background: var(--canvas-dark); }
[data-theme="light"] .aiw-frame--canvas { background: var(--canvas-light); }
/* decks paint their own background and fill their box */
.aiw-frame--deck { height: 100%; background: var(--canvas-dark); }

/* R-115: a live page between its chat card and its side viewer tab (frame-host.js parkFrame), for the rest of the
   task: off screen, rendered (a hidden frame loses its scroll when it moves on) and at its own size (frame-host sets
   the slot's width and height), so the page sees no resize */
.aiw-frame-park {
    position: fixed;
    top: 0;
    left: -100000px;
    overflow: hidden;
    pointer-events: none;
}

.aiw-frame-park > .aiw-frame { height: 100%; }

/* ---- gallery (FR §3.5) ---------------------------------------------------------------------- */
.aiw-gallery {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
    margin: var(--space-1) 0;
}

.aiw-gallery > .aiw-gallery__tile { margin: 0; }
.aiw-gallery__tile .aiw-card__body { max-height: 320px; }

@media (max-width: 480px) {
    .aiw-gallery { grid-template-columns: minmax(0, 1fr); }
}

/* ---- control chip (FR §3.6, §6.3): 32 px tonal pills ------------------------------------------ */
.aiw-control-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    max-width: 100%;
    min-height: 32px;
    margin: var(--space-1) 0;
    padding: 0 14px 0 12px;
    border: 0;
    border-radius: var(--radius-pill);
    background: var(--c-surface-high);
    color: var(--c-on-2);
    font: var(--t-body-s);
    cursor: pointer;
    transition: background-color var(--dur-1) var(--ease-standard), color var(--dur-1) var(--ease-standard), box-shadow var(--dur-2) var(--ease-standard);
}

.aiw-control-chip:hover { color: var(--c-on); background: var(--c-surface-highest); }
.aiw-control-chip[disabled] { cursor: default; opacity: 0.7; }
.aiw-control-chip[data-flash="true"] { color: var(--c-on-accent-container); background: var(--c-accent-container); box-shadow: 0 0 0 1.5px var(--c-accent); }
.aiw-control-chip__icon { color: var(--c-accent); }
.aiw-control-chip__text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Side viewer (Ray 2026-10-30): a display placed there only is a one-line reference; the model's side_viewer
   actions are chips too (an "Opened" one is a button, the others only say what happened). */
.aiw-viewer-ref { display: flex; }
.aiw-viewer-ref, .aiw-viewer-chip { width: fit-content; }
.aiw-viewer-ref__go { flex-shrink: 0; color: var(--c-accent-text); font-weight: 500; }
.aiw-viewer-chip:not(button) { cursor: default; }
.aiw-viewer-chip:not(button):hover { color: var(--c-on-2); background: var(--c-surface-high); }

/* ---- action / outline menu (portaled): the menu surface ---------------------------------------- */
.aiw-menu {
    position: fixed;
    z-index: var(--z-lightbox);
    display: flex;
    flex-direction: column;
    min-width: 200px;
    max-width: min(320px, calc(100vw - 16px));
    max-height: min(60vh, 420px);
    overflow-y: auto;
    padding: 6px;
    border: 0;
    border-radius: var(--radius-md);
    background: var(--c-surface-raised);
    box-shadow: var(--elev-2);
}

.aiw-menu__item {
    display: block;
    width: 100%;
    min-height: 40px;
    padding: 0 12px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--c-on);
    font: var(--t-body-m);
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}

.aiw-menu__item:hover { background: var(--c-hover); }
.aiw-menu__item:focus-visible { outline: none; background: var(--c-hover); box-shadow: inset 0 0 0 2px var(--c-focus); }

/* ---- the stage (FR §6.1; brief §6.10): the low surface, tabs that join the header -------------- */
.aiw-stage {
    position: fixed;
    top: 0;
    bottom: 0;
    right: 0;
    z-index: var(--z-stage);
    display: flex;
    flex-direction: column;
    background: var(--c-surface-low);
    color: var(--c-on);
}

/* min(): the JS clamp is re-applied on resize (L08); until it runs the pane never takes the chat's 480 px */
.aiw-stage--pane {
    width: min(var(--aiw-stage-w, 45vw), max(360px, 100vw - 480px));
    box-shadow: -1px 0 0 var(--c-outline-variant);
}

/* the chat column reflows next to the desktop pane and keeps its max width */
body.aiw-stage-open #main-area { margin-right: min(var(--aiw-stage-w, 45vw), max(360px, 100vw - 480px)); }
body.aiw-stage-resizing { cursor: col-resize; user-select: none; }
body.aiw-stage-resizing .aiw-frame { pointer-events: none; }

.aiw-stage--sheet {
    left: 0;
    width: 100%;
    height: 100dvh;
}

body.aiw-stage-sheet-open { overflow: hidden; }

.aiw-stage__divider {
    position: absolute;
    top: 0;
    bottom: 0;
    left: -4px;
    z-index: 1;
    width: 8px;
    cursor: col-resize;
    background: transparent;
    transition: background-color var(--dur-1) var(--ease-standard);
}

.aiw-stage__divider:hover,
.aiw-stage__divider:focus-visible { outline: none; background: color-mix(in srgb, var(--c-accent) 25%, transparent); }

/* The tab strip (browser-like tabs, Ray 2026-10-30): Back (sheet), the tabs, ✕ (pane: closes the viewer). */
.aiw-stage__tabs {
    display: flex;
    align-items: flex-end;
    gap: var(--space-1);
    min-height: 48px;
    padding: 0 6px 0 8px;
    background: var(--c-surface-low);
}

.aiw-stage__tabs > .aiw-stage__closetab,
.aiw-stage__tabs > .aiw-stage__back { flex: 0 0 auto; align-self: center; }

/* ✕ closes the whole viewer (kept in the DOM, drawn as an icon): a hairline sets it apart from the last tab's × */
.aiw-stage__tabs > .aiw-stage__close {
    position: relative;
    flex: 0 0 auto;
    align-self: center;
    width: 36px;
    height: 36px;
    margin-left: var(--space-1);
    padding: 0;
    border-radius: var(--radius-pill);
    font-size: 0;
}

.aiw-stage__tabs > .aiw-stage__close::before {
    content: "";
    position: absolute;
    top: 25%;
    bottom: 25%;
    left: calc(-1 * var(--space-1));
    border-left: 1px solid var(--c-outline-variant);
}

.aiw-stage__tabs > .aiw-stage__close::after {
    content: ""; width: 18px; height: 18px; background: currentColor;
    -webkit-mask: var(--icon-x) center / contain no-repeat; mask: var(--icon-x) center / contain no-repeat;
}

.aiw-stage__strip {
    display: flex;
    flex: 1 1 auto;
    align-items: flex-end;
    gap: 2px;
    min-width: 0;
    padding-top: var(--space-1);
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
}

.aiw-stage__strip::-webkit-scrollbar { height: 6px; }

/* tabs shrink (down to 100 px, 120 px for touch) before the strip scrolls; the active one keeps its width */
.aiw-stage__tab {
    position: relative;
    display: flex;
    flex: 0 1 auto;
    align-items: center;
    max-width: 220px;
    min-width: 100px;
    height: 38px;
    border: 0;
    border-radius: 10px 10px 0 0;
    color: var(--c-on-2);
    transition: background-color var(--dur-1) var(--ease-standard), color var(--dur-1) var(--ease-standard);
}

.aiw-stage__tab:hover { background: var(--c-hover); color: var(--c-on); }

/* the active tab joins the header below it, with a gold edge at its top (inset from each side) */
.aiw-stage__tab[data-active="true"] {
    flex-shrink: 0;
    background: var(--c-surface);
    color: var(--c-on);
}

.aiw-stage__tab[data-active="true"]::before {
    content: "";
    position: absolute;
    left: 10px;
    right: 10px;
    top: 0;
    height: 2px;
    border-radius: 0 0 2px 2px;
    background: var(--c-accent);
}

.aiw-stage__tab-main {
    display: inline-flex;
    flex: 1 1 auto;
    align-items: center;
    gap: 8px;
    min-width: 0;
    height: 100%;
    padding: 0 var(--space-1) 0 12px;
    border: 0;
    border-radius: inherit;
    background: transparent;
    color: inherit;
    font: var(--t-label-m);
    cursor: pointer;
}

.aiw-stage__tab-main:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--c-focus); }
.aiw-stage__tab-icon { flex: 0 0 auto; color: var(--c-on-3); font-size: 12px; }
.aiw-stage__tab[data-active="true"] .aiw-stage__tab-icon { color: var(--c-accent); }
.aiw-stage__tab-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.aiw-stage__tab-close {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    margin-right: 6px;
    border: 0;
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--c-on-3);
    font-size: 0;
    line-height: 0;
    cursor: pointer;
}

.aiw-stage__tab-close::before {
    content: ""; width: 14px; height: 14px; background: currentColor;
    -webkit-mask: var(--icon-x) center / contain no-repeat; mask: var(--icon-x) center / contain no-repeat;
}

.aiw-stage__tab-close:hover { background: var(--c-hover); color: var(--c-on); }

/* "Close tab" for the keyboard (the × in a tab is pointer-only): takes no room until it has focus */
.aiw-stage__closetab:not(:focus) {
    position: absolute;
    width: 1px;
    min-width: 0;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

@media (pointer: coarse) {
    .aiw-stage__tabs { min-height: 52px; }
    .aiw-stage__tab { min-width: 120px; height: 44px; }
    .aiw-stage__tab-close { width: 40px; height: 40px; margin-right: 0; }
    .aiw-stage__tabs > .aiw-stage__close { width: 40px; height: 40px; }
}

/* the header: the title, the deck controls, the placement switch and the actions on the card surface */
.aiw-stage__bar {
    container-type: inline-size;
    container-name: aiw-stage-bar;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    min-height: 48px;
    padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
    border-bottom: 1px solid var(--c-outline-variant);
    background: var(--c-surface);
    font: var(--t-body-s);
}

.aiw-stage__title {
    flex: 1 1 120px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font: var(--t-title-m);
    font-size: 0.875rem;
}

.aiw-stage__deck { display: inline-flex; align-items: center; gap: var(--space-1); }
.aiw-stage__counter { min-width: 48px; text-align: center; color: var(--c-on-2); font-variant-numeric: tabular-nums; }
.aiw-stage__deck > :is(.aiw-stage__prev, .aiw-stage__next) { font-size: 1.125rem; }

/* the current slide's steps (only when it has more than one): dots, or "step 3/14" for long ones */
.aiw-stage__steps { display: inline-flex; align-items: center; gap: 4px; margin-right: var(--space-1); }
.aiw-stage__step-dot { width: 6px; height: 6px; border-radius: 50%; box-shadow: inset 0 0 0 1px var(--c-on-3); }
.aiw-stage__step-dot[data-on="true"] { box-shadow: none; background: var(--c-accent); }
.aiw-stage__steps-text { color: var(--c-on-3); font-size: 11px; font-variant-numeric: tabular-nums; }

/* the offline copy's download icon (an inline SVG in the header's icon buttons) */
.aiw-stage__actions svg { display: block; }

.aiw-stage__outline {
    max-width: 190px;
    height: 32px;
    padding: 0 30px 0 10px;
    border: 1px solid var(--c-outline-variant);
    border-radius: var(--radius-sm);
    background: var(--c-surface-low) var(--chev) no-repeat right 8px center / 16px 16px;
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    color: var(--c-on);
    font: var(--t-body-s);
    text-overflow: ellipsis;
}

.aiw-stage__actions { display: inline-flex; align-items: center; gap: 2px; }
.aiw-stage__back { font-weight: 600; color: var(--c-on); }

/* X46: the title stops asking for its 120 px basis in the pane (it takes what is left and ellipsizes).
   Below 600 px of bar content width the deck controls take a second row, so the title keeps readable
   room next to the actions (the default 45% pane at 1440 px stays one row). ✕ and the sheet's Back sit
   in the tab strip above the header. */
.aiw-stage--pane .aiw-stage__title { flex-basis: 0; }

@container aiw-stage-bar (max-width: 599.98px) {
    .aiw-stage--pane .aiw-stage__deck { order: 1; flex: 1 0 100%; }
}

/* The sheet (brief §6.10, audit A3): the deck controls take a second row of their own, so the title, the placement
   switch and the actions share row one (the title takes what is left; under 72 px the actions wrap instead). */
.aiw-stage--sheet .aiw-stage__title { flex-basis: 72px; }
.aiw-stage--sheet .aiw-stage__deck { order: 1; flex: 1 0 100%; }

.aiw-stage__body {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    background: var(--c-surface);
}

.aiw-stage__body .aiw-frame { height: 100%; }
.aiw-stage__body[data-view="deck"] { display: flex; align-items: center; justify-content: center; background: var(--canvas-dark); }
.aiw-stage__body[data-view="deck"] .aiw-frame { width: 100%; height: 100%; }
/* audio, video, archives and the file card in the side viewer (Ray 2026-11-07: "All files in the side viewer"):
   a video fills the tab (letterboxed on black), an audio player and a file card sit in its middle, an archive's
   listing scrolls inside the tab */
.aiw-stage__body[data-view="media"],
.aiw-stage__body[data-view="binary"] { display: flex; flex-direction: column; justify-content: center; }
.aiw-stage__body[data-view="media"] > .aiwv-media--video { flex: 1 1 auto; min-height: 0; }
.aiw-stage__body[data-view="media"] > .aiwv-media--audio,
.aiw-stage__body[data-view="binary"] > .aiwv-filecard { flex: 0 0 auto; margin: 0 var(--space-4); }
.aiw-stage__body[data-view="archive"] { display: flex; flex-direction: column; }
.aiw-stage__body[data-view="archive"] > .aiwv-archive { flex: 1 1 auto; min-height: 0; }
.aiw-stage__error { padding: var(--space-4); color: var(--c-on-2); }

/* ---- lightbox (FR §5.1), portaled to body, z 45 (below system notices, I1) ------------------------ */
/* fixed colours: a media viewer stays dark in both themes, its controls white on dark glass (L10) */
.aiw-lightbox {
    position: fixed;
    inset: 0;
    z-index: var(--z-lightbox);
    display: flex;
    flex-direction: column;
    background: var(--lightbox-scrim);
    color: #fff;
}

.aiw-lightbox:focus { outline: none; }
body.aiw-lightbox-open { overflow: hidden; }

.aiw-lightbox__bar {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
}

.aiw-lightbox__spacer { flex: 1 1 auto; }
.aiw-lightbox__counter { font: var(--t-label-m); font-variant-numeric: tabular-nums; opacity: 0.85; }

/* Shared round look of the bar buttons and the side arrows; each sets its own font-size below,
   so no property is defined twice for one selector (I7). */
.aiw-lightbox__btn,
.aiw-lightbox__nav {
    min-width: 40px;
    height: 40px;
    padding: 0 var(--space-3);
    border: 0;
    border-radius: var(--radius-pill);
    background: rgb(20 19 17 / 0.78);
    color: #fff;
    font-family: inherit;
    cursor: pointer;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    transition: background-color var(--dur-1) var(--ease-standard);
}
.aiw-lightbox__btn { font-size: 14px; }
.aiw-lightbox__btn:hover, .aiw-lightbox__nav:hover { background: rgb(48 46 42 / 0.88); }

.aiw-lightbox__btn:focus-visible,
.aiw-lightbox__nav:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* The side arrows, on the stage's middle edge. */
.aiw-lightbox__nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 22px;
}

.aiw-lightbox__stage {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    touch-action: none;
}

.aiw-lightbox__img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transform-origin: center center;
    transition: transform 0.12s ease-out;
    user-select: none;
    -webkit-user-drag: none;
    cursor: zoom-in;
}

.aiw-lightbox[data-zoomed="true"] .aiw-lightbox__img { cursor: grab; transition: none; }

/* an SVG's canvas on the dark scrim (lightbox.js): light, dark, the app's (auto) or checker (with the card's) */
.aiw-lightbox__img[data-bg="light"] { background: var(--canvas-light); }
.aiw-lightbox__img[data-bg="dark"] { background: var(--canvas-dark); }
.aiw-lightbox__img[data-bg="auto"] { background: var(--c-surface); }

.aiw-lightbox__nav--prev { left: var(--space-3); }
.aiw-lightbox__nav--next { right: var(--space-3); }

.aiw-lightbox__caption {
    padding: var(--space-2) var(--space-4) var(--space-4);
    text-align: center;
    font: var(--t-body-s);
    opacity: 0.9;
}

/* ---- utilities ----------------------------------------------------------------------------- */
.aiw-offscreen {
    position: fixed;
    left: -9999px;
    top: 0;
    width: 1px;
    height: 1px;
    opacity: 0;
}

/* ---- forced colours: the line icons are masks over currentColor, which forced colours would paint in Canvas ---- */
@media (forced-colors: active) {
    .aiw-card__icon::before,
    .aiw-card__actions > :is(.aiw-act-copy, .aiw-act-download, .aiw-act-outline, .aiw-act-background, .aiw-act-newtab, .aiw-act-fullscreen, .aiw-card__more)::before,
    .aiw-card__notes-chevron::before,
    .aiw-stage__tabs > .aiw-stage__close::after,
    .aiw-stage__tab-close::before { forced-color-adjust: none; background: ButtonText; }
    /* keyboard focus drawn with a box-shadow or a tint, which forced colours drop: a real outline (final review client-3) */
    .aiw-card__notes-toggle:focus-visible,
    .aiw-card__notes-body:focus-visible,
    .aiw-card__resume:focus-visible,
    .aiw-card__staged:focus-visible,
    .aiw-menu__item:focus-visible,
    .aiw-stage__divider:focus-visible,
    .aiw-stage__tab-main:focus-visible { outline: 2px solid Highlight; outline-offset: -2px; }
}

/* ---- reduced motion (FR §10.4): no shimmer, no lightbox zoom animation ------------------------ */
@media (prefers-reduced-motion: reduce) {
    .aiw-card__skeleton { animation: none; background: var(--c-surface-high); }
    .aiw-lightbox__img { transition: none; }
}
