/* ==========================================================================
   THE CONVERSE BUILDER - commands (owned by the commands lane from wave 2b)

   The hover toolbar (bible 5.2), the right-click menu (5.3), the + picker
   (5.4), the Ctrl+K palette, the ? sheet and the inline popovers. Every
   overlay is position: fixed and placed by convcommands.js (open at the
   pointer, flip at the edges). Built on the platform's menu surface tokens
   (--theme-background-float / --theme-surface-hover / --theme-focus-ring,
   the wf-action-menu family) - no Bootstrap dropdown classes. Tokens only,
   no raw colours; prefers-reduced-motion turns every animation off.
   ========================================================================== */

/* No z-index here on purpose: the layer must not open a stacking context, so its fixed overlays
   stack against the whole page (above the drawer and the canvas). */
.conv-cmd-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.conv-cmd-layer > * {
    pointer-events: auto;
}

/* A dialog opened from the drawer (Find pictures, the asset picker, a shared modal) lives inside the
   drawer's stacking context, so its backdrop cannot rise above these page-level fixed layers - they would float over the
   dialog. While any of them is open the canvas's command layers step aside (2026-11-01: the hover toolbar showed over Find
   pictures and over the picture picker). A new overlay a drawer can open joins this list. */
body:has(.conv-dialog-backdrop, .fmp-overlay, .wf-modal-backdrop, .modal-backdrop) .conv-cmd-layer {
    visibility: hidden;
}

/* ── The hover toolbar ─────────────────────────────────────────────────── */

.conv-cmd-bar {
    position: fixed;
    left: -9999px;
    top: -9999px;
    z-index: 1040;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    border: 1px solid var(--theme-border);
    border-radius: var(--theme-radius-button);
    background: var(--theme-background-float);
    box-shadow: var(--theme-shadow-lg);
    opacity: 0;
    pointer-events: none;
    transform: translateY(4px);
    transition: opacity var(--conv-motion), transform var(--conv-motion);
}

.conv-cmd-bar:empty {
    display: none;
}

.conv-cmd-bar[data-visible="true"] {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.conv-cmd-bar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: calc(var(--theme-radius-button) - 2px);
    background: transparent;
    color: var(--theme-text-secondary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: background var(--conv-motion), color var(--conv-motion);
}

.conv-cmd-bar-btn:hover,
.conv-cmd-bar-btn:focus-visible {
    background: var(--theme-surface-hover);
    color: var(--theme-text-emphasis);
    outline: none;
}

.conv-cmd-bar-btn:focus-visible {
    box-shadow: var(--theme-focus-ring);
}

.conv-cmd-bar-btn[aria-disabled="true"] {
    color: var(--theme-text-muted);
    opacity: 0.5;
    cursor: default;
}

.conv-cmd-bar-btn[aria-disabled="true"]:hover {
    background: transparent;
    color: var(--theme-text-muted);
}

.conv-cmd-bar-sep {
    width: 1px;
    height: 18px;
    margin: 0 2px;
    background: var(--theme-border-subtle);
}

/* ── Click-away layer ──────────────────────────────────────────────────── */

.conv-cmd-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1045;
    background: transparent;
}

.conv-cmd-backdrop.is-dim {
    background: color-mix(in srgb, var(--theme-text) 18%, transparent);
    backdrop-filter: blur(1px);
}

/* ── The menu ──────────────────────────────────────────────────────────── */

.conv-cmd-menu {
    position: fixed;
    left: -9999px;
    top: -9999px;
    z-index: 1050;
    display: flex;
    flex-direction: column;
    min-width: 248px;
    max-width: 340px;
    max-height: min(80vh, 560px);
    overflow-y: auto;
    padding: 4px;
    border: 1px solid var(--theme-border);
    border-radius: var(--theme-radius);
    background: var(--theme-background-float);
    box-shadow: var(--theme-shadow-lg);
    font-family: var(--theme-font);
    color: var(--theme-text);
    animation: conv-cmd-rise 120ms ease-out;
    outline: none;
}

.conv-cmd-menu.is-sub {
    z-index: 1051;
    min-width: 232px;
    animation: conv-cmd-fade 120ms ease-out;
}

@keyframes conv-cmd-rise {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes conv-cmd-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

.conv-cmd-menu-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px 8px;
    margin-bottom: 2px;
    border-bottom: 1px solid var(--theme-border-subtle);
    color: var(--theme-text-secondary);
    font-size: var(--theme-font-size-xs);
    font-weight: 600;
    min-width: 0;
}

.conv-cmd-menu-head-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 22px;
    height: 22px;
    border-radius: var(--theme-radius-button);
    background: var(--conv-fam-soft, var(--theme-surface-hover));
    color: var(--conv-fam, var(--theme-text-secondary));
    font-size: 0.75rem;
}

.conv-cmd-menu-head-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conv-cmd-sep {
    height: 0;
    margin: 4px 6px;
    border-top: 1px solid var(--theme-border-subtle);
}

.conv-cmd-item {
    display: grid;
    grid-template-columns: 18px 1fr auto;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 32px;
    padding: 5px 10px;
    border: 0;
    border-radius: var(--theme-radius-button);
    background: none;
    color: var(--theme-text);
    font-family: inherit;
    font-size: var(--theme-font-size-sm);
    text-align: left;
    cursor: pointer;
}

.conv-cmd-item:hover,
.conv-cmd-item.is-open {
    background: var(--theme-surface-hover);
}

.conv-cmd-item:focus-visible {
    outline: 0;
    background: var(--theme-surface-hover);
    box-shadow: var(--theme-focus-ring);
}

.conv-cmd-item-icon {
    width: 18px;
    text-align: center;
    color: var(--theme-text-muted);
    font-size: 0.875rem;
}

.conv-cmd-item-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.conv-cmd-item-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conv-cmd-item-detail,
.conv-cmd-item-why {
    color: var(--theme-text-muted);
    font-size: var(--theme-font-size-xs);
    line-height: 1.3;
    white-space: normal;
}

.conv-cmd-item-detail {
    font-family: var(--theme-font-mono);
}

/* A disabled line is shown, never hidden - its reason sits right under the label. */
.conv-cmd-item.is-disabled {
    color: var(--theme-text-muted);
    cursor: default;
}

.conv-cmd-item.is-disabled .conv-cmd-item-icon {
    opacity: 0.55;
}

.conv-cmd-item.is-disabled .conv-cmd-item-why {
    display: none;
}

.conv-cmd-item.is-disabled:hover .conv-cmd-item-why,
.conv-cmd-item.is-disabled:focus-visible .conv-cmd-item-why {
    display: block;
}

.conv-cmd-item.is-danger:not(.is-disabled),
.conv-cmd-item.is-danger:not(.is-disabled) .conv-cmd-item-icon {
    color: var(--theme-danger);
}

.conv-cmd-item-chevron {
    color: var(--theme-text-muted);
    font-size: 0.7rem;
}

.conv-cmd-kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    padding: 1px 6px;
    border: 1px solid var(--theme-border-subtle);
    border-radius: 4px;
    background: var(--theme-background-subtle);
    color: var(--theme-text-muted);
    font-family: var(--theme-font-mono);
    font-size: var(--theme-font-size-xs);
    line-height: 1.5;
    white-space: nowrap;
}

/* ── Floating cards: picker, palette, sheet, popover ───────────────────── */

.conv-cmd-pop {
    position: fixed;
    z-index: 1052;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--theme-border);
    border-radius: var(--theme-radius);
    background: var(--theme-background-float);
    box-shadow: var(--theme-shadow-lg);
    font-family: var(--theme-font);
    color: var(--theme-text);
    animation: conv-cmd-rise 120ms ease-out;
}

/* The + picker is a BOXED SCROLL (Kirk, 2026-10-04: "the ASK needs to be boxed scroll - goes off screen"): the search,
   the tabs and the key hints stay put and only the list scrolls, inside the panel. The CSS cap below is the tallest it
   ever grows; where it opens, the placement (OverlayPlacement, set inline by convcommands.js) caps it again to the room
   on the side it opens - above its anchor near the bottom of the screen, shorter when neither side has the room. */
.conv-cmd-picker {
    left: -9999px;
    top: -9999px;
    width: min(420px, calc(100vw - 32px));
    max-height: min(560px, calc(100vh - 32px));
    overflow: hidden;
}

/* The picker's and the palette's own wrappers carry the flex column through, so the list - not the panel - is what
   takes the height that is left (an unstyled block here let the list spill past the panel and off the screen). */
.conv-pick,
.conv-palette {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
}

.conv-pick > .conv-pick-search,
.conv-pick > .conv-pick-tabs,
.conv-pick > .conv-pick-foot,
.conv-palette > .conv-pick-search {
    flex: none;
}

.conv-cmd-popover {
    left: -9999px;
    top: -9999px;
    width: min(340px, calc(100vw - 32px));
    max-height: min(460px, calc(100vh - 32px));
    padding: 12px;
    gap: 10px;
}

.conv-cmd-palette {
    left: 50%;
    top: 12vh;
    width: min(560px, calc(100vw - 32px));
    max-height: min(520px, 76vh);
    overflow: hidden;
    transform: translateX(-50%);
    animation: conv-cmd-fade 120ms ease-out;
}

.conv-cmd-sheet {
    left: 50%;
    top: 50%;
    width: min(760px, calc(100vw - 32px));
    max-height: calc(100vh - 64px);
    transform: translate(-50%, -50%);
    animation: conv-cmd-fade 120ms ease-out;
}

/* The search row (picker, palette, chooser) */
.conv-pick-search {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--theme-border-subtle);
    color: var(--theme-text-muted);
}

.conv-pick-search.is-small {
    padding: 6px 8px;
    border: 1px solid var(--theme-border-subtle);
    border-radius: var(--theme-radius-button);
}

.conv-pick-input {
    flex: 1;
    min-width: 0;
    border: 0;
    background: transparent;
    color: var(--theme-text-emphasis);
    font: inherit;
    font-size: var(--theme-font-size-base);
    outline: none;
}

.conv-pick-input::placeholder {
    color: var(--theme-text-placeholder);
}

.conv-pick-tabs {
    display: flex;
    gap: 2px;
    padding: 6px 8px 0;
    border-bottom: 1px solid var(--theme-border-subtle);
    overflow-x: auto;
    scrollbar-width: none;
}

.conv-pick-tab {
    flex: 0 0 auto;
    padding: 6px 10px;
    border: 0;
    border-bottom: 2px solid transparent;
    background: none;
    color: var(--theme-text-secondary);
    font: inherit;
    font-size: var(--theme-font-size-sm);
    cursor: pointer;
    transition: color var(--conv-motion), border-color var(--conv-motion);
}

.conv-pick-tab:hover {
    color: var(--theme-text-emphasis);
}

.conv-pick-tab.is-active {
    border-bottom-color: var(--conv-ask);
    color: var(--theme-text-emphasis);
    font-weight: 600;
}

.conv-pick-tab:focus-visible {
    outline: 0;
    box-shadow: var(--theme-focus-ring);
}

.conv-pick-list,
.conv-palette-list,
.conv-popover-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 6px;
}

.conv-popover-list {
    padding: 0;
    max-height: 300px;
}

.conv-pick-group {
    padding: 8px 8px 4px;
    color: var(--theme-text-muted);
    font-size: var(--theme-font-size-xs);
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* "From your skills" (packs as bundles): a pack's presets open under its name and icon in the Library tab. */
.conv-pick-group--pack {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--theme-text-secondary);
    letter-spacing: 0.02em;
    text-transform: none;
}

.conv-pick-group--pack .bi {
    color: var(--conv-act);
    font-size: 13px;
}

.conv-pick-tile {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 7px 8px;
    border: 0;
    border-radius: var(--theme-radius-button);
    background: none;
    color: var(--theme-text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.conv-pick-tile:hover,
.conv-pick-tile.is-active {
    background: var(--theme-surface-hover);
}

.conv-pick-tile.is-active {
    box-shadow: inset 2px 0 0 var(--conv-fam, var(--conv-ask));
}

.conv-pick-tile:focus-visible {
    outline: 0;
    box-shadow: var(--theme-focus-ring);
}

.conv-pick-tile-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    border-radius: var(--theme-radius-button);
    background: var(--conv-fam-soft, var(--theme-surface-hover));
    color: var(--conv-fam, var(--theme-text-secondary));
    font-size: 0.95rem;
}

.conv-pick-tile-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.conv-pick-tile-name {
    color: var(--theme-text-emphasis);
    font-size: var(--theme-font-size-sm);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conv-pick-tile-hint {
    color: var(--theme-text-muted);
    font-size: var(--theme-font-size-xs);
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.conv-pick-empty {
    padding: 20px 12px;
    color: var(--theme-text-muted);
    font-size: var(--theme-font-size-sm);
    text-align: center;
    line-height: 1.5;
}

.conv-pick-foot {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    padding: 8px 12px;
    border-top: 1px solid var(--theme-border-subtle);
    color: var(--theme-text-muted);
    font-size: var(--theme-font-size-xs);
}

.conv-pick-foot .conv-cmd-kbd {
    margin-right: 2px;
}

/* The palette's rows reuse the menu line */
.conv-palette-item {
    display: grid;
    grid-template-columns: 18px 1fr auto;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 34px;
    padding: 6px 10px;
    border: 0;
    border-radius: var(--theme-radius-button);
    background: none;
    color: var(--theme-text);
    font: inherit;
    font-size: var(--theme-font-size-sm);
    text-align: left;
    cursor: pointer;
}

.conv-palette-item:hover,
.conv-palette-item.is-active {
    background: var(--theme-surface-hover);
}

.conv-palette-item.is-disabled {
    color: var(--theme-text-muted);
}

/* The sheet */
.conv-sheet {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.conv-sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px 10px 16px;
    border-bottom: 1px solid var(--theme-border-subtle);
}

.conv-sheet-title {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--theme-text-emphasis);
    font-size: var(--theme-font-size-lg);
    font-weight: 600;
}

.conv-sheet-cols {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 8px 24px;
    padding: 8px 16px 16px;
    overflow-y: auto;
}

.conv-sheet-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 5px 8px;
    border-radius: var(--theme-radius-button);
    font-size: var(--theme-font-size-sm);
}

.conv-sheet-row:hover {
    background: var(--theme-surface-hover);
}

.conv-sheet-keys {
    display: inline-flex;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* The popover */
.conv-popover {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
}

.conv-popover-title {
    color: var(--theme-text-emphasis);
    font-size: var(--theme-font-size-sm);
    font-weight: 600;
}

.conv-popover-message {
    color: var(--theme-text);
    font-size: var(--theme-font-size-sm);
    line-height: 1.5;
}

.conv-popover-input {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--theme-border);
    border-radius: var(--theme-radius-button);
    background: var(--theme-background-raised);
    color: var(--theme-text-emphasis);
    font: inherit;
    font-size: var(--theme-font-size-sm);
    outline: none;
}

.conv-popover-input:focus {
    border-color: var(--conv-ask);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--conv-ask) 18%, transparent);
}

.conv-popover-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.conv-popover-btn {
    padding: 6px 12px;
    border: 1px solid var(--theme-border);
    border-radius: var(--theme-radius-button);
    background: var(--theme-background-raised);
    color: var(--theme-text);
    font: inherit;
    font-size: var(--theme-font-size-sm);
    cursor: pointer;
    transition: background var(--conv-motion), border-color var(--conv-motion);
}

.conv-popover-btn:hover:not(:disabled) {
    background: var(--theme-surface-hover);
}

.conv-popover-btn:focus-visible {
    outline: 0;
    box-shadow: var(--theme-focus-ring);
}

.conv-popover-btn:disabled {
    opacity: 0.5;
    cursor: default;
}

.conv-popover-btn.is-primary {
    border-color: var(--conv-ask);
    background: var(--conv-ask);
    color: var(--theme-text-on-primary);
}

.conv-popover-btn.is-primary:hover:not(:disabled) {
    background: var(--theme-primary-hover);
}

.conv-popover-btn.is-danger {
    border-color: var(--theme-danger);
    background: var(--theme-danger);
    color: var(--theme-text-on-danger);
}

.conv-popover-btn.is-danger:hover {
    background: color-mix(in srgb, var(--theme-danger) 85%, var(--theme-text));
}

/* ── Small screens and reduced motion ──────────────────────────────────── */

@media (max-width: 640px) {
    .conv-cmd-menu {
        min-width: 220px;
        max-width: calc(100vw - 16px);
    }

    .conv-sheet-cols {
        grid-template-columns: 1fr;
    }
}

@media (prefers-reduced-motion: reduce) {
    .conv-cmd-bar,
    .conv-cmd-menu,
    .conv-cmd-pop,
    .conv-pick-tab,
    .conv-popover-btn {
        animation: none;
        transition: none;
    }
}
