/* ---- tool pages: the studio layout (Components/Tools/ToolLayout.razor) ----------------------------------------------
   A header with the setup strip, then a controls panel beside a sticky result stage. The panel's run button is pinned to
   its foot, so a long form never hides it; the stage stays in view while the form scrolls. One column below 1100px. */

/* No bottom padding: sticky offsets are measured inside the scroller's padding, which would float the pinned run button
   above the viewport's edge with fields showing under it. The ::after puts the breathing room back. */
.tool { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1rem; padding: 1rem 1.5rem 0; }
.tool::after { content: ""; display: block; height: .5rem; }
/* The page scrolls as a whole; nothing in it gives up height to fit the viewport. */
.tool > * { flex-shrink: 0; }

/* ---- header: a compact PageHero (ui-kit.css) in the page's sidebar-group colour ---- */
.tool > .hero { margin: 0; }
.tool__hero .tool__status { max-width: 30rem; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }

/* ---- setup strip: project, server, workflow ---- */
.tool__setup { display: flex; flex-wrap: wrap; align-items: center; gap: .45rem; margin-top: -.25rem; }
.tool-pick {
    position: relative; display: inline-flex; align-items: center; gap: .4rem; min-height: 2.25rem; margin: 0;
    padding: .15rem .2rem .15rem .75rem; border: 1px solid var(--rl-border); border-radius: 999px;
    background: var(--rl-surface); box-shadow: var(--rl-shadow-sm); font-size: .85rem;
    transition: border-color var(--rl-dur), box-shadow var(--rl-dur);
}
.tool-pick:hover { border-color: var(--rl-border-strong); }
.tool-pick:focus-within { border-color: var(--rl-accent); box-shadow: var(--rl-ring); }
.tool-pick__label { color: var(--rl-text-muted); font-size: .7rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.tool-pick select {
    max-width: 15rem; min-height: 0; padding: .25rem 1.7rem .25rem .3rem; border: 0; border-radius: 999px;
    background-color: transparent; color: var(--rl-text); font: inherit; cursor: pointer; box-shadow: none;
}
.tool-pick select:focus-visible { outline: none; box-shadow: none; background-color: transparent; }

.tool-pop { position: relative; }
.tool-pop > summary { list-style: none; cursor: pointer; padding-right: .85rem; user-select: none; }
.tool-pop > summary::-webkit-details-marker { display: none; }
.tool-pop[open] > summary { border-color: var(--rl-accent); }
.tool-pop__icon { width: 1rem; height: 1rem; color: var(--rl-accent); flex: none; margin-left: -.2rem; }
.tool-pop__value { max-width: 13rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--rl-text); }
.tool-pop__panel {
    position: absolute; top: calc(100% + .45rem); right: 0; z-index: 40; width: min(27rem, 88vw);
    display: flex; flex-direction: column; gap: .65rem; padding: .9rem 1rem;
    border: 1px solid var(--rl-border); border-radius: var(--rl-radius); background: var(--rl-surface); box-shadow: var(--rl-shadow-lg);
    animation: tool-pop-in var(--rl-dur) var(--rl-ease) both;
}
.tool-pop__panel h2 { margin: 0; font-size: 1rem; }
.tool-pop__panel p { margin: 0; }
.tool-pop + .tool-pop .tool-pop__panel { right: 0; }
@keyframes tool-pop-in { from { opacity: 0; transform: translateY(-4px) scale(.98); } }

/* ---- notices above the workspace ---- */
.tool > .admin__status, .tool > .card__empty, .tool > .card { margin: 0; }

/* ---- workspace ---- */
.tool__body { display: grid; grid-template-columns: minmax(23rem, 33rem) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
/* For a page whose stage is a wide table rather than a picture. */
.tool--wide-stage .tool__body { grid-template-columns: minmax(21rem, 27rem) minmax(0, 1fr); }

.tool__panel {
    position: relative; display: flex; flex-direction: column; min-width: 0;
    border: 1px solid var(--rl-border); border-radius: var(--rl-radius); background: var(--rl-surface); box-shadow: var(--rl-shadow-sm);
    animation: rl-rise .22s var(--rl-ease) both;
}
.tool__controls { display: flex; flex-direction: column; min-width: 0; }

.tool__actions {
    position: sticky; bottom: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem;
    padding: .75rem 1rem; border-top: 1px solid var(--rl-border); border-radius: 0 0 var(--rl-radius) var(--rl-radius);
    background: color-mix(in srgb, var(--rl-surface) 90%, transparent);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 -8px 18px -14px rgb(0 0 0 / .45);
}
.tool__actions .btn--primary { flex: 1 1 10rem; min-height: 2.6rem; font-size: 1rem; }
.tool__actions .btn--danger { min-height: 2.6rem; }
.tool__actions > .card__meta, .tool__actionsNote { flex-basis: 100%; margin: 0; font-size: .8rem; color: var(--rl-text-muted); }
.tool__actions label { display: inline-flex; align-items: center; gap: .4rem; font-size: .88rem; }

.unreal-products { list-style: none; margin: .75rem 0 0; padding: 0; display: flex; flex-direction: column; gap: .35rem; max-height: 14rem; overflow: auto; }
.unreal-products .btn { width: 100%; justify-content: flex-start; text-align: left; }
.unreal-products .is-current { border-color: var(--rl-accent); color: var(--rl-text); }
.unreal-kit { justify-content: space-between; gap: .5rem; }
.unreal-kit small { color: var(--rl-text-muted); font-weight: 600; }
.unreal-menu__back { position: fixed; inset: 0; z-index: 40; }
.unreal-menu {
    position: fixed; z-index: 41; display: flex; flex-direction: column; align-items: stretch; gap: .35rem;
    width: 14rem; padding: .7rem; border: 1px solid var(--rl-border); border-radius: var(--rl-radius);
    background: var(--rl-surface); box-shadow: var(--rl-shadow-lg, 0 12px 32px rgba(0, 0, 0, .28));
}
.unreal-menu p { margin: 0; font-weight: 700; }
.unreal-menu small { color: var(--rl-text-muted); }
.unreal-menu .btn { width: 100%; justify-content: center; }

.unreal-board { display: flex; flex-direction: column; gap: .85rem; }
.unreal-row { display: grid; gap: .75rem; grid-template-columns: minmax(0, 1fr); }
.unreal-row--pair { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.unreal-slot { margin: 0; display: flex; flex-direction: column; gap: .4rem; min-width: 0; }
.unreal-slot__view {
    position: relative; height: 14rem; display: flex; align-items: center; justify-content: center; overflow: hidden;
    border: 1px solid var(--rl-border); border-radius: var(--rl-radius); background: var(--rl-surface);
}
.unreal-slot__view img, .unreal-slot__view model-viewer { width: 100%; height: 100%; object-fit: contain; }
.unreal-slot__view progress { position: absolute; left: .6rem; right: .6rem; bottom: .55rem; }
.unreal-slot figcaption { display: flex; flex-direction: column; gap: .1rem; font-size: .85rem; }
.unreal-slot figcaption span { color: var(--rl-text-muted); }
.unreal-slot .btn { align-self: flex-start; }
.unreal-card__file { display: flex; align-items: center; justify-content: center; padding: .75rem; text-align: center; }
@media (max-width: 720px) { .unreal-row--pair { grid-template-columns: minmax(0, 1fr); } }

/* ---- the stage ---- */
.tool__stage {
    position: sticky; top: 0; display: flex; flex-direction: column; gap: .85rem; min-width: 0;
    min-height: min(34rem, calc(100dvh - 9rem)); max-height: calc(100dvh - 2rem); overflow: auto; padding: 1rem;
    border: 1px solid var(--rl-border); border-radius: var(--rl-radius);
    background-color: var(--rl-surface-sunken);
    background-image: radial-gradient(color-mix(in srgb, var(--rl-text) 10%, transparent) 1px, transparent 1.2px);
    background-size: 18px 18px;
}
.tool__stage > .card, .tool__stage > section { margin: 0; flex: none; }
/* The bare stage speaks EmptyState's big form (ui-kit.css): the icon in a dashed, tinted tile over the sentence. The
   tile is the svg's own box, so the markup stays one element; its fill hides the stage's dot grid behind it. */
.tool__empty {
    margin: auto; display: flex; flex-direction: column; align-items: center; gap: .8rem; max-width: 24rem; padding: 1.25rem 1rem;
    color: var(--rl-text-muted); text-align: center; font-size: .9rem;
}
.tool__empty p { margin: 0; line-height: 1.55; }
.tool__emptyIcon {
    box-sizing: border-box; width: 3.6rem; height: 3.6rem; padding: 1rem; border-radius: 16px;
    border: 1px dashed color-mix(in srgb, var(--rl-accent) 55%, var(--rl-border));
    background: color-mix(in srgb, var(--rl-accent) 9%, var(--rl-surface)); color: var(--rl-accent);
}
.tool__empty:not(:only-child) { display: none; }
/* A page's own empty state, for a stage that is never bare (the edit page's hidden mask canvas). */
.tool__empty.tool__empty--keep { display: flex; }
.tool__stage .mask-painter { max-width: none; }

.tool__stage .comfy-results { grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); }
.tool__stage .comfy-result img { max-height: calc(100dvh - 14rem); object-fit: contain; }
.tool__stage .comfy-result figcaption { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; word-break: normal; }

/* "Running…": a card with the accent hairline every running thing wears, so it reads as part of the job status above it. */
.tool-busy {
    display: flex; align-items: center; gap: .75rem;
    box-shadow: inset 0 2px 0 color-mix(in srgb, var(--rl-accent) 75%, transparent), var(--rl-shadow-sm);
}
.tool-busy p { margin: 0; color: var(--rl-text); }

/* The running job (Pages/Comfy/ComfyJobStatus.razor, a SectionCard): its clock beside the title, a live dot while it runs. */
.comfy-job__clock {
    display: inline-flex; align-items: center; gap: .45rem; color: var(--rl-text-muted); font-size: .82rem;
    font-variant-numeric: tabular-nums;
}
.comfy-job .comfy-progress { margin: 0; }

/* A footnote in a result card: where the files went, or that they did not. The icon takes the line's tone (ui-tone--N). */
.tool-note { display: flex; align-items: flex-start; gap: .45rem; margin: 0; color: var(--rl-text-muted); font-size: .84rem; line-height: 1.45; }
.tool-note > svg { flex: none; width: .95rem; height: .95rem; margin-top: .14rem; color: var(--tone, var(--rl-accent)); }
.tool-note code { overflow-wrap: anywhere; }

/* What a result card says about the run beside its title: how many and how long. */
.tool__stage .ui-card__actions .ui-chip { font-variant-numeric: tabular-nums; }
.tool-busy__spin {
    flex: none; width: 1.1rem; height: 1.1rem; border-radius: 50%;
    border: 2px solid color-mix(in srgb, var(--rl-accent) 25%, transparent); border-top-color: var(--rl-accent);
    animation: rl-spin .8s linear infinite;
}

/* ---- sections inside the controls panel (Components/Tools/ToolSection.razor) ----
   Each group reads as a small Panel card: a sentence-case title, and given an icon, that icon in a square tinted with
   the group's tone, plus a short hairline of the tone on the divider above. A group with an icon and no Tone of its
   own takes one from its place in the panel; :where() keeps that at no specificity, so an explicit ui-tone--N wins. */
.tool-sec { position: relative; padding: .95rem 1.05rem; border-top: 1px solid var(--rl-border); min-width: 0; }
.tool-sec:first-child { border-top: 0; }
:where(.tool__controls > .tool-sec:nth-child(5n + 1)) { --tone: var(--rl-chart-1); }
:where(.tool__controls > .tool-sec:nth-child(5n + 2)) { --tone: var(--rl-chart-2); }
:where(.tool__controls > .tool-sec:nth-child(5n + 3)) { --tone: var(--rl-chart-3); }
:where(.tool__controls > .tool-sec:nth-child(5n + 4)) { --tone: var(--rl-chart-4); }
:where(.tool__controls > .tool-sec:nth-child(5n + 5)) { --tone: var(--rl-chart-5); }
.tool-sec--toned::before {
    content: ""; position: absolute; top: -1px; left: 1.05rem; width: 2.4rem; height: 2px; border-radius: 0 0 2px 2px;
    background: color-mix(in srgb, var(--tone, var(--rl-accent)) 80%, transparent); pointer-events: none;
}
.tool-sec__head { display: flex; align-items: center; gap: .55rem; min-width: 0; margin: 0 0 .75rem; }
.tool-sec__title { min-width: 0; margin: 0; color: var(--rl-text); font-size: .92rem; font-weight: 650; line-height: 1.3; }
.tool-sec__ico.ui-ico { width: 1.6rem; height: 1.6rem; border-radius: .45rem; }
.tool-sec__ico.ui-ico svg { width: .9rem; height: .9rem; }
/* What the group is set to, as a quiet pill, so a folded group still says it at a glance. */
.tool-sec__summary {
    margin-left: auto; min-width: 0; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    padding: .08rem .55rem; border-radius: 999px; background: var(--rl-surface-sunken);
    color: var(--rl-text-muted); font-size: .76rem; font-weight: 500; font-variant-numeric: tabular-nums;
}
.tool-sec__aside { margin-left: auto; display: flex; align-items: center; gap: .4rem; }
.tool-sec__summary + .tool-sec__aside { margin-left: .5rem; }
.tool-sec__hint { margin: -.3rem 0 .75rem; color: var(--rl-text-muted); font-size: .82rem; line-height: 1.45; }
.tool-sec__body > :last-child { margin-bottom: 0; }

/* A folding group: the whole head is the toggle, with the chevron at its far end pointing the way it will move. */
.tool-sec--fold { padding-block: .75rem; }
.tool-sec--fold > summary {
    list-style: none; cursor: pointer; margin: -.3rem -.45rem; padding: .3rem .45rem; border-radius: 10px; user-select: none;
    transition: background-color var(--rl-dur) var(--rl-ease);
}
.tool-sec--fold > summary::-webkit-details-marker { display: none; }
.tool-sec--fold > summary:hover { background: var(--rl-surface-sunken); }
.tool-sec--fold > summary:focus-visible { outline: 2px solid var(--rl-accent); outline-offset: 1px; }
.tool-sec--fold[open] > summary { margin-bottom: .45rem; }
.tool-sec__chevron {
    flex: none; width: .95rem; height: .95rem; margin-left: auto; color: var(--rl-text-muted);
    transform: rotate(90deg); transition: transform var(--rl-dur) var(--rl-ease), color var(--rl-dur) var(--rl-ease);
}
.tool-sec__summary + .tool-sec__chevron { margin-left: .15rem; }
.tool-sec--fold > summary:hover .tool-sec__chevron { color: var(--rl-text); }
.tool-sec--fold[open] > summary .tool-sec__chevron { transform: rotate(-90deg); }
.tool-sec--fold[open] > .tool-sec__body { animation: tool-fold-in .2s var(--rl-ease) both; }
@keyframes tool-fold-in { from { opacity: 0; transform: translateY(-3px); } }

/* The lead group (the prompt) reads first: a wash of its tone along its top edge and a roomier text box. */
.tool-sec--lead {
    --lead-wash: var(--rl-accent);
    background: linear-gradient(to bottom, color-mix(in srgb, var(--lead-wash) 8%, transparent), transparent 5.5rem);
    border-radius: var(--rl-radius) var(--rl-radius) 0 0;
}
.tool-sec--lead.tool-sec--toned { --lead-wash: var(--tone, var(--rl-accent)); }
.tool-sec--lead textarea { font-size: 1rem; line-height: 1.5; }

/* ---- fields: the app's .field, made dense for a narrow panel ---- */
.tool .field { max-width: none; margin-bottom: .75rem; gap: .3rem; }
.tool .field label { font-size: .84rem; }
.tool .field small { font-size: .8rem; line-height: 1.4; }
.tool .field small.warn { color: var(--rl-danger); }
.tool .field select, .tool .field textarea { width: 100%; max-width: none; box-sizing: border-box; }
.tool .field input:not([type=checkbox], [type=radio], [type=range], [type=file], [type=color]) { width: 100%; max-width: none; box-sizing: border-box; }
.tool .field input[type=range] { width: 100%; }
.tool .field > label:has(> input[type=checkbox]), .tool .field > label:has(> input[type=radio]) {
    display: flex; align-items: center; gap: .5rem; font-weight: 600; cursor: pointer;
}
.tool .field--row { display: grid; grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr)); gap: .6rem .75rem; align-items: start; }
.tool .field--row > span { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.tool .field--row > small { grid-column: 1 / -1; }
.tool .admin__status { margin: 0 0 .75rem; font-size: .88rem; }
/* In a kit card the card's own gap spaces it. */
.tool .ui-card > .admin__status { margin: 0; }
.tool .ui-card .ui-form .field { margin-bottom: .6rem; }

/* A grid of whole .field blocks, for settings that are each one short control. */
.tool-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr)); gap: 0 .75rem; align-items: start; }
.tool-grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tool-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tool-grid > .tool-grid__wide { grid-column: 1 / -1; }

/* One repeated group inside a section, such as a dialogue role. */
.tool-sub { padding: .6rem .7rem .1rem; margin-bottom: .6rem; border: 1px solid var(--rl-border); border-radius: var(--rl-radius); background: var(--rl-surface-raised); }
.tool-sub:last-child { margin-bottom: 0; }

/* A file input with the chosen name and size beside it. */
.tool-file { display: flex; flex-direction: column; gap: .3rem; }
.tool-file__name { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }

/* ---- chips: short exclusive choices, and the aspect ratios ---- */
.tool-chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.tool-chip {
    display: inline-flex; align-items: center; gap: .4rem; min-height: 2rem; padding: .28rem .7rem;
    border: 1px solid var(--rl-border); border-radius: 999px; background: var(--rl-surface-raised);
    color: var(--rl-text); font: inherit; font-size: .84rem; line-height: 1.2; cursor: pointer; white-space: nowrap;
    transition: background-color var(--rl-dur), border-color var(--rl-dur), color var(--rl-dur), transform var(--rl-dur) var(--rl-ease);
}
.tool-chip:hover:not(:disabled) { border-color: var(--rl-border-strong); }
.tool-chip:active:not(:disabled) { transform: scale(.97); }
.tool-chip:focus-visible { outline: 2px solid var(--rl-accent); outline-offset: 2px; }
.tool-chip:disabled { opacity: .5; cursor: not-allowed; }
.tool-chip--on, .tool-chip--on:hover:not(:disabled) {
    border-color: var(--rl-accent); background: color-mix(in srgb, var(--rl-accent) 14%, var(--rl-surface)); color: var(--rl-accent); font-weight: 600;
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--rl-accent) 45%, transparent);
}
.tool-chip--ratio { gap: .3rem; padding-inline: .5rem; font-variant-numeric: tabular-nums; }
.tool-ratio { display: inline-block; flex: none; border: 1.5px solid currentColor; border-radius: 2px; opacity: .75; }

.tool-size__raw { display: flex; align-items: center; gap: .35rem; margin-top: .2rem; }
.tool .tool-size__raw input { width: 5.75rem; }
.tool-size__swap {
    display: inline-grid; place-items: center; width: 1.9rem; height: 1.9rem; border: 0; border-radius: 8px;
    background: none; color: var(--rl-text-muted); font: inherit; font-size: 1rem; cursor: pointer;
    transition: background-color var(--rl-dur), color var(--rl-dur);
}
.tool-size__swap:hover:not(:disabled) { background: var(--rl-surface-sunken); color: var(--rl-text); }
.tool-size__unit { margin-left: .2rem; color: var(--rl-text-muted); font-size: .8rem; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---- narrow: one column, the stage under the form ---- */
@media (max-width: 1100px) {
    .tool__body { grid-template-columns: minmax(0, 1fr); }
    .tool__stage { position: static; min-height: 0; max-height: none; overflow: visible; }
    .tool__stage:has(> .tool__empty:only-child) { display: none; }
}
@media (max-width: 640px) {
    .tool { padding: .75rem .75rem 0; gap: .75rem; }
    .tool__setup { width: 100%; }
    .tool-pick select { max-width: 10rem; }
    .tool-pop__panel { right: auto; left: 0; }
    .tool-grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
    .tool__panel, .tool-pop__panel, .tool-sec--fold[open] > .tool-sec__body { animation: none; }
    .tool-sec__chevron, .tool-chip { transition: none; }
}

/* ---- assets pane (Components/Assets/AssetPane.razor) --------------------------------------------------------------------------
   A tool's shelf of library files: a strip above the workspace on the form pages, a folding panel in the corner on the full-screen
   editors. Each tile previews on click and carries one "Use as ..." chip per field that takes it; a file no field takes is dimmed,
   not hidden - it is there to look at. */
.apane {
    display: flex; flex-direction: column; gap: .55rem; padding: .55rem .75rem;
    border: 1px solid var(--rl-border); border-radius: var(--rl-radius); background: var(--rl-surface); box-shadow: var(--rl-shadow-sm);
}
.apane.is-empty:not(.apane--float) { padding: .4rem .75rem; background: var(--rl-surface-raised); box-shadow: none; }
.apane__head { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .75rem; min-width: 0; }
.apane__toggle {
    display: inline-flex; align-items: center; gap: .4rem; padding: .25rem .5rem .25rem .3rem; border: 0; border-radius: 8px;
    background: none; color: var(--rl-text); font: inherit; font-weight: 700; font-size: .9rem; cursor: pointer;
}
.apane__toggle:hover { background: var(--rl-surface-sunken); }
.apane__toggle svg { width: 1.05rem; height: 1.05rem; color: var(--rl-accent); flex: none; }
.apane__toggle .apane__caret { width: .9rem; height: .9rem; color: var(--rl-text-muted); transition: transform var(--rl-dur) var(--rl-ease); }
.apane.is-open .apane__caret { transform: rotate(90deg); }
.apane--float:not(.is-open) .apane__caret { transform: rotate(-90deg); }
.apane__count {
    min-width: 1.35rem; padding: 0 .4rem; border-radius: 999px; background: var(--rl-accent); color: var(--rl-accent-contrast);
    font-size: .74rem; line-height: 1.35rem; text-align: center; font-variant-numeric: tabular-nums;
}
.apane__hint { flex: 1 1 14rem; min-width: 0; color: var(--rl-text-muted); font-size: .82rem; }
.apane__tools { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; margin-left: auto; }
.apane__tools .btn { display: inline-flex; align-items: center; gap: .3rem; }
.apane__tools svg { width: .95rem; height: .95rem; }
.apane__upload { position: relative; overflow: hidden; cursor: pointer; }
.apane__upload input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0; }
.apane__upload.is-busy { opacity: .7; pointer-events: none; }
.apane__status { margin: 0; font-size: .82rem; color: var(--rl-ok); }
.apane__status--bad { color: var(--rl-danger); }

.apane__list {
    display: flex; gap: .6rem; margin: 0; padding: .1rem .1rem .45rem; list-style: none;
    overflow-x: auto; scroll-snap-type: x proximity; overscroll-behavior-x: contain;
}
.apane__item {
    position: relative; flex: 0 0 13.5rem; display: flex; flex-direction: column; gap: .4rem; padding: .4rem;
    border: 1px solid var(--rl-border); border-radius: 10px; background: var(--rl-surface-raised); scroll-snap-align: start;
    transition: border-color var(--rl-dur), box-shadow var(--rl-dur);
}
.apane__item:hover { border-color: color-mix(in srgb, var(--rl-accent) 45%, var(--rl-border)); }
.apane__item.is-fresh { border-color: var(--rl-accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--rl-accent) 30%, transparent); }
.apane__item.is-idle .apane__thumb { opacity: .7; }
.apane__thumb {
    position: relative; display: flex; align-items: center; justify-content: center; height: 6.5rem; padding: 0; overflow: hidden;
    border: 1px solid var(--rl-border); border-radius: 8px; cursor: zoom-in;
    background: repeating-conic-gradient(var(--rl-surface-sunken) 0% 25%, var(--rl-surface) 0% 50%) 50% / .9rem .9rem;
}
.apane__thumb img, .apane__thumb video { width: 100%; height: 100%; object-fit: contain; display: block; pointer-events: none; }
.apane__play {
    position: absolute; display: grid; place-items: center; width: 2rem; height: 2rem; border-radius: 50%;
    background: rgba(0, 0, 0, .55); color: #fff; font-size: .8rem;
}
.apane__glyph, .apick__glyph {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .25rem; width: 100%; height: 100%;
    background: color-mix(in srgb, var(--file-tone, var(--rl-text-muted)) 12%, var(--rl-surface)); color: var(--file-tone, var(--rl-text-muted));
}
.apane__glyph svg, .apick__glyph svg { width: 1.9rem; height: 1.9rem; }
.apane__glyph b, .apick__glyph b { font-size: .72rem; letter-spacing: .06em; }
.apane__body { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.apane__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .85rem; font-weight: 600; }
.apane__meta { color: var(--rl-text-muted); font-size: .75rem; }
.apane__uses { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .25rem; }
.apane__use {
    padding: .2rem .55rem; border: 1px solid color-mix(in srgb, var(--rl-accent) 45%, var(--rl-border)); border-radius: 999px;
    background: color-mix(in srgb, var(--rl-accent) 10%, var(--rl-surface)); color: var(--rl-text); font: inherit; font-size: .76rem;
    cursor: pointer; transition: background var(--rl-dur), border-color var(--rl-dur);
}
.apane__use:hover:not(:disabled) { background: var(--rl-accent); border-color: var(--rl-accent); color: var(--rl-accent-contrast); }
.apane__use:disabled { opacity: .55; cursor: default; }
.apane__none { color: var(--rl-text-muted); font-size: .74rem; font-style: italic; }
.apane__remove {
    position: absolute; top: .65rem; right: .65rem; display: grid; place-items: center; width: 1.5rem; height: 1.5rem; padding: 0;
    border: 1px solid var(--rl-border); border-radius: 50%; background: var(--rl-surface); color: var(--rl-text-muted);
    font-size: .7rem; line-height: 1; cursor: pointer; opacity: 0; transition: opacity var(--rl-dur);
}
.apane__item:hover .apane__remove, .apane__remove:focus-visible { opacity: 1; }
.apane__remove:hover { color: var(--rl-danger); border-color: var(--rl-danger); }
@media (hover: none) { .apane__remove { opacity: 1; } }

/* The full-screen editors: a pill in the corner that opens upward into a panel. Absolute, not fixed: the containing block is
   .app__main, which is the work area beside the sidebar, so the pill never covers the rail. */
.apane--float {
    position: absolute; left: 1rem; bottom: 1rem; z-index: 60; width: auto; max-width: calc(100vw - 2rem);
    padding: .3rem .4rem; box-shadow: var(--rl-shadow-lg);
}
.apane--float.is-open { width: min(26rem, calc(100vw - 2rem)); max-height: min(70vh, 40rem); padding: .55rem .65rem; }
.apane--float .apane__hint { flex-basis: 100%; order: 3; }
.apane--float .apane__list { flex-direction: column; overflow-x: hidden; overflow-y: auto; min-height: 0; padding-right: .2rem; }
.apane--float .apane__item { flex: none; flex-direction: row; align-items: flex-start; }
.apane--float .apane__thumb { flex: 0 0 5.5rem; height: 4.5rem; }
.apane--float .apane__body { flex: 1; }
.apane--float .apane__remove { top: .3rem; right: .3rem; }

/* ---- library picker (Components/Assets/LibraryPicker.razor) ---- */
.apick { width: min(58rem, 100%); }
.apick__filters { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; padding: .65rem 1.1rem 0; }
.apick__filters input[type=search] { flex: 1 1 16rem; min-width: 0; }
.apick__body { min-height: 12rem; }
.apick__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); gap: .55rem; margin: .5rem 0 0; padding: 0; list-style: none; }
.apick__item {
    position: relative; display: flex; flex-direction: column; gap: .25rem; width: 100%; padding: .35rem; text-align: left;
    border: 1px solid var(--rl-border); border-radius: 10px; background: var(--rl-surface-raised); color: var(--rl-text); font: inherit; cursor: pointer;
}
.apick__item:hover:not(:disabled) { border-color: color-mix(in srgb, var(--rl-accent) 50%, var(--rl-border)); }
.apick__item.is-on { border-color: var(--rl-accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--rl-accent) 35%, transparent); }
.apick__item.is-in { opacity: .5; cursor: default; }
.apick__item img, .apick__glyph { width: 100%; height: 6rem; object-fit: contain; border-radius: 7px; background: var(--rl-surface-sunken); }
.apick__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .82rem; font-weight: 600; }
.apick__item small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--rl-text-muted); font-size: .72rem; }
.apick__tick {
    position: absolute; top: .55rem; left: .55rem; display: grid; place-items: center; min-width: 1.4rem; height: 1.4rem; padding: 0 .3rem;
    border: 1px solid var(--rl-border); border-radius: 6px; background: var(--rl-surface); font-size: .75rem; font-weight: 700;
}
.apick__item.is-on .apick__tick { background: var(--rl-accent); border-color: var(--rl-accent); color: var(--rl-accent-contrast); }
.apick__more { display: flex; justify-content: center; padding: .75rem 0 0; }
.apick__foot { display: flex; align-items: center; justify-content: flex-end; gap: .5rem; padding: .7rem 1.1rem; border-top: 1px solid var(--rl-border); }
.apick__foot .card__meta { margin-right: auto; }

/* ---- the shared preview (Components/Assets/AssetPreviewDialog.razor): the formats the lightbox did not draw before ---- */
.lbx__table {
    width: min(100%, 72rem); max-height: 100%; overflow: auto; border-radius: .4rem; background: #16161c; color: #e8e8ee;
    box-shadow: 0 1rem 3rem rgba(0, 0, 0, .55);
}
.lbx__table table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.lbx__table th, .lbx__table td { padding: .35rem .6rem; border-bottom: 1px solid #2a2a33; text-align: left; vertical-align: top; white-space: pre-wrap; }
.lbx__table th { position: sticky; top: 0; background: #22222b; font-weight: 700; }
.lbx__table tbody tr:nth-child(even) td { background: #1b1b22; }
.lbx__note { margin: 0; padding: .5rem .75rem; color: #a0a0ad; font-size: .8rem; }
.lbx__frame { width: min(100%, 72rem); height: 100%; border: 0; border-radius: .4rem; background: #fff; box-shadow: 0 1rem 3rem rgba(0, 0, 0, .55); }
.lbx__none { display: flex; flex-direction: column; align-items: center; gap: .75rem; color: #e8e8ee; }
.lbx__toggle { border: 0; background: none; font: inherit; cursor: pointer; padding: 0; }
.lbx__bar { flex-wrap: wrap; padding: 0 1rem; }

/* ---- library: type cards, the selection bar and the "Use in a tool" picker (Components/Pages/Library.razor) -------------------
   The type is a row of cards, each with its icon, its count under the other filters, and a tooltip saying what lands in it. The
   tooltip is CSS so it shows on keyboard focus too, without the browser's slow native title. */
.kind-cards { display: flex; flex-wrap: wrap; gap: .45rem; }
.kind-card {
    position: relative; display: inline-flex; align-items: center; gap: .45rem; min-height: 2.5rem; padding: .35rem .7rem .35rem .55rem;
    border: 1px solid var(--rl-border); border-radius: 10px; background: var(--rl-surface-raised); color: var(--rl-text);
    font: inherit; font-size: .86rem; font-weight: 600; cursor: pointer;
    transition: border-color var(--rl-dur), background var(--rl-dur), box-shadow var(--rl-dur), transform var(--rl-dur) var(--rl-ease);
}
.kind-card svg { width: 1.15rem; height: 1.15rem; flex: none; color: var(--rl-accent); }
.kind-card:hover { border-color: color-mix(in srgb, var(--rl-accent) 50%, var(--rl-border)); transform: translateY(-1px); }
.kind-card:focus-visible { outline: none; box-shadow: var(--rl-ring); }
.kind-card.is-on {
    border-color: var(--rl-accent); background: color-mix(in srgb, var(--rl-accent) 14%, var(--rl-surface));
    box-shadow: 0 0 0 1px var(--rl-accent) inset;
}
.kind-card.is-empty { opacity: .5; }
.kind-card.is-empty svg { color: var(--rl-text-muted); }
.kind-card__count {
    min-width: 1.5rem; padding: 0 .4rem; border-radius: 999px; background: var(--rl-surface-sunken); color: var(--rl-text-muted);
    font-size: .74rem; line-height: 1.3rem; text-align: center; font-variant-numeric: tabular-nums;
}
.kind-card.is-on .kind-card__count { background: var(--rl-accent); color: var(--rl-accent-contrast); }
.kind-card[data-tip]::after {
    content: attr(data-tip); position: absolute; top: calc(100% + .5rem); left: 50%; z-index: 30; width: max-content; max-width: 17rem;
    padding: .45rem .6rem; border: 1px solid var(--rl-border); border-radius: 8px; background: var(--rl-surface); color: var(--rl-text);
    box-shadow: var(--rl-shadow-lg); font-size: .78rem; font-weight: 400; line-height: 1.4; text-align: left; white-space: normal;
    opacity: 0; transform: translate(-50%, -3px); pointer-events: none; transition: opacity .12s ease, transform .12s ease;
}
.kind-card[data-tip]::before {
    content: ""; position: absolute; top: calc(100% + .2rem); left: 50%; z-index: 31; width: .6rem; height: .6rem;
    border-left: 1px solid var(--rl-border); border-top: 1px solid var(--rl-border); background: var(--rl-surface);
    opacity: 0; transform: translateX(-50%) rotate(45deg); pointer-events: none; transition: opacity .12s ease;
}
.kind-card:hover::after, .kind-card:focus-visible::after { opacity: 1; transform: translate(-50%, 0); transition-delay: .25s; }
.kind-card:hover::before, .kind-card:focus-visible::before { opacity: 1; transition-delay: .25s; }
.kind-cards > .kind-card:first-child::after { left: 0; transform: translate(0, -3px); }
.kind-cards > .kind-card:first-child:hover::after, .kind-cards > .kind-card:first-child:focus-visible::after { transform: none; }

.library__upload { position: relative; overflow: hidden; display: inline-flex; align-items: center; gap: .3rem; cursor: pointer; }
.library__upload svg { width: .95rem; height: .95rem; }
.library__upload input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0; }
.library__upload.is-busy { opacity: .7; pointer-events: none; }

/* The bar that appears once something is ticked: the count on the left, the actions in one row on the right. */
.library__selection {
    position: sticky; top: .5rem; z-index: 5; display: flex; flex-direction: row; flex-wrap: wrap; align-items: center;
    justify-content: flex-start; gap: .5rem .75rem; padding: .55rem .8rem; text-align: left;
    border-color: color-mix(in srgb, var(--rl-accent) 45%, var(--rl-border)); box-shadow: 0 4px 16px rgba(0, 0, 0, .2);
}
.library__selectionCount { font-weight: 700; }
.library__selectionActions { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; margin-left: auto; }
.library__selectionActions .btn { display: inline-flex; align-items: center; gap: .35rem; width: auto; margin: 0; }
.library__selectionActions svg { width: 1rem; height: 1rem; }
.library__move {
    min-height: 2.25rem; padding: .3rem .5rem; border: 1px solid var(--rl-border); border-radius: 8px;
    background: var(--rl-surface-raised); color: var(--rl-text); font: inherit; font-size: .88rem;
}
.library__confirm p { margin: 0 0 .6rem; }

.library__tools { width: min(56rem, 100%); }
.library__toolGroup { margin-top: .9rem; }
.library__toolGroup h3 { margin: 0 0 .4rem; font-size: .74rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--rl-text-muted); }
.library__toolGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(14.5rem, 1fr)); gap: .45rem; }
.library__tool {
    display: grid; grid-template-columns: auto 1fr auto; grid-template-areas: "icon name fit" "icon takes takes"; align-items: center;
    gap: .1rem .55rem; padding: .55rem .65rem; text-align: left; border: 1px solid var(--rl-border); border-radius: 10px;
    background: var(--rl-surface-raised); color: var(--rl-text); font: inherit; cursor: pointer;
    transition: border-color var(--rl-dur), background var(--rl-dur);
}
.library__tool:hover:not(:disabled) { border-color: var(--rl-accent); background: color-mix(in srgb, var(--rl-accent) 8%, var(--rl-surface-raised)); }
.library__tool svg { grid-area: icon; width: 1.4rem; height: 1.4rem; color: var(--rl-accent); }
.library__toolName { grid-area: name; font-weight: 600; font-size: .9rem; }
.library__tool small { grid-area: takes; color: var(--rl-text-muted); font-size: .75rem; }
.library__toolFit { grid-area: fit; font-size: .7rem; font-weight: 700; color: var(--rl-ok); white-space: nowrap; }
.library__tool.is-off { opacity: .45; cursor: not-allowed; }
.library__tool.is-off svg, .library__tool.is-off .library__toolFit { color: var(--rl-text-muted); }

/* The project's files, listed after the shelf when the work belongs to a project. */
.apane__proj {
    max-width: 11rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 .45rem; border-radius: 999px;
    border: 1px solid var(--rl-border); color: var(--rl-text-muted); font-size: .72rem; font-weight: 600; line-height: 1.35rem;
}
.apane__group { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .5rem; margin-top: .1rem; font-size: .8rem; font-weight: 700; color: var(--rl-text-muted); }
.apane__group svg { width: .95rem; height: .95rem; color: var(--rl-accent); flex: none; }
.apane__group a { color: var(--rl-text); }
.apane__group .apane__groupLink { margin-left: auto; font-weight: 400; color: var(--rl-text-muted); }
.apane__empty { margin: 0; color: var(--rl-text-muted); font-size: .8rem; }
.apane__item.is-project { background: color-mix(in srgb, var(--rl-accent) 5%, var(--rl-surface-raised)); }
.apane .tool-pick { min-height: 1.95rem; font-size: .8rem; }
.apane .tool-pick select { max-width: 10rem; }

/* The chat: a pill on its own row below the composer that opens into a strip in the flow. Under the greeting the strip opens into
   the empty page beneath; in a running chat the foot grows and lifts the composer, so it never runs off either edge. Smaller tiles,
   since the thread is the point. */
.chat-assets { display: flex; flex-direction: column; gap: .5rem; }
.apane--compact:not(.is-open) { align-self: flex-start; padding: .15rem .3rem; background: var(--rl-surface); box-shadow: none; }
.apane--compact .apane__item { flex-basis: 11.5rem; }
.apane--compact .apane__thumb { height: 4.75rem; }
