/* --------------------------------------------------------------------------
   menu-manager.css
   Styles for the Menu Manager Ops page + MenuItemEditDialog + PinToMenu
   button chrome. Loaded globally from index.html - used only by the
   Menu Manager page and the pin button which may appear anywhere.

   --theme-* tokens only. Zero hex outside comments.
   ---------------------------------------------------------------------- */

/* -- Menu Manager page -------------------------------------------------- */

.menu-mgr-bucket {
    margin-top: 1.5rem;
    background-color: var(--theme-background-raised);
    border: 1px solid var(--theme-border-subtle);
    border-radius: var(--theme-radius);
    padding: 0.75rem 1rem;
}

.menu-mgr-bucket-title {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    margin: 0 0 0.5rem 0;
    font-size: var(--theme-font-size-base);
    color: var(--theme-text-emphasis);
}

.menu-mgr-bucket-count {
    margin-left: auto;
    padding: 0 0.5rem;
    border-radius: var(--theme-radius);
    background-color: var(--theme-background-subtle);
    color: var(--theme-text-muted);
    font-size: var(--theme-font-size-xs);
    font-weight: 400;
}

.menu-mgr-empty {
    color: var(--theme-text-muted);
    font-style: italic;
    padding: 0.5rem 0;
}

.menu-mgr-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.menu-mgr-list.readonly .menu-mgr-row {
    opacity: 0.85;
}

.menu-mgr-row {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.5rem 0.75rem;
    background-color: var(--theme-background);
    border: 1px solid var(--theme-border-subtle);
    border-radius: var(--theme-radius);
    transition: var(--theme-transition);
}

.menu-mgr-row:hover {
    background-color: var(--theme-background-hover);
}

.menu-mgr-row-icon {
    width: 2rem;
    text-align: center;
    color: var(--theme-primary);
    font-size: 1.1rem;
    flex-shrink: 0;
}

.menu-mgr-row-body {
    flex: 1 1 auto;
    min-width: 0;
}

.menu-mgr-row-name {
    font-weight: 600;
    color: var(--theme-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.menu-mgr-row-meta {
    font-size: var(--theme-font-size-xs);
    color: var(--theme-text-muted);
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    align-items: center;
}

.menu-mgr-type-badge {
    padding: 0.0625rem 0.375rem;
    border-radius: var(--theme-radius);
    background-color: var(--theme-primary-muted);
    color: var(--theme-primary);
    font-weight: 500;
}

.menu-mgr-row-actions {
    display: flex;
    align-items: center;
    gap: 0.125rem;
    flex-shrink: 0;
}

/* -- Edit dialog sections (redesign) --------------------------------------
   Light, top-to-bottom section bands so a first-timer reads the dialog as a
   sequence: What is it -> What it's called -> Where it shows -> Placement ->
   Advanced. Power controls live under the Advanced <details>. */

.mid-section {
    padding: 0.75rem 0;
    border-top: 1px solid var(--theme-border-subtle);
}

.mid-section:first-of-type {
    border-top: 0;
    padding-top: 0.25rem;
}

.mid-section-head {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-weight: 600;
    font-size: var(--theme-font-size-sm);
    color: var(--theme-text-emphasis);
    margin-bottom: 0.25rem;
}

.mid-section-hint {
    font-size: var(--theme-font-size-xs);
    color: var(--theme-text-muted);
    margin-bottom: 0.625rem;
}

/* Internal name reads as a code-level identifier. */
.mid-mono {
    font-family: var(--theme-font-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
}

/* Per-language editor - the "little control" lifted from StepDialog. A faint
   inset rail visually groups the language rows + Auto-Translate button. */
.mid-lang-block {
    padding: 0.5rem 0 0.5rem 0.75rem;
    border-left: 2px solid var(--theme-border-subtle);
}

/* Two side-by-side fields (icon + display order) on roomy widths; stacks on
   narrow viewports. */
.mid-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

@media (max-width: 30rem) {
    .mid-row-2 { grid-template-columns: 1fr; }
}

/* Advanced disclosure - quiet by default. */
.mid-advanced {
    margin-top: 0.5rem;
    border-top: 1px solid var(--theme-border-subtle);
    padding-top: 0.75rem;
}

.mid-advanced > summary {
    cursor: pointer;
    list-style: revert;
}

.mid-advanced > summary:hover {
    color: var(--theme-primary);
}

.mid-advanced-body {
    padding: 0.625rem 0 0.25rem 0.25rem;
}

/* -- Edit dialog icon preview ------------------------------------------- */

.menu-mgr-icon-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.menu-mgr-icon-preview {
    font-size: 1.25rem;
    color: var(--theme-primary);
    width: 1.75rem;
    text-align: center;
    flex-shrink: 0;
}

/* -- PinToMenu button --------------------------------------------------- */

.wf-pin-group {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.wf-pin-pinned {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.625rem;
    background-color: var(--theme-primary-muted);
    color: var(--theme-primary);
    border-radius: var(--theme-radius);
    font-size: var(--theme-font-size-sm);
}

.wf-pin-error {
    font-size: var(--theme-font-size-xs);
    color: var(--theme-danger);
    margin-left: 0.25rem;
}

/* -- Page header (reused pattern) ---------------------------------------
   The .wf-page-header box itself is root.css's alone (portal-look-and-feel 3.7: no ruled
   line under a page header). This file used to restyle it UNSCOPED - every stylesheet
   loads on every page, so its bottom rule came back on every page in the Portal
   (Tests/ConversationBuilderCssOwnershipTests found it). Only the Menu Manager's own
   descendants stay here. */

.wf-page-header h2 {
    margin: 0;
    flex: 1 1 auto;
    min-width: 0;
    color: var(--theme-text-emphasis);
}

.wf-page-header-actions {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    flex-shrink: 0;
}

/* -- Picker affordances (Phase 2c.4 polish) ---------------------------- */

.menu-mgr-picker-loading {
    display: flex;
    align-items: center;
    color: var(--theme-text-muted);
    font-style: italic;
    background-color: var(--theme-background-subtle);
}

.menu-mgr-picker-raw {
    margin-top: 0.5rem;
}

.menu-mgr-picker-raw summary {
    cursor: pointer;
    color: var(--theme-text-muted);
    padding: 0.25rem 0;
}

.menu-mgr-picker-raw summary:hover {
    color: var(--theme-primary);
}

/* -- Wizard data-source sub-header (Phase 2c.4 wizard polish) ----------- */

.ef-wizard-ds-sub-header {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0;
    font-weight: 600;
    font-size: var(--theme-font-size-xs);
    color: var(--theme-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

/* -- Drag-reorder (Phase 2c.6) ---------------------------------------- */

.menu-mgr-row[draggable="true"] {
    cursor: grab;
}

.menu-mgr-row[draggable="true"]:active {
    cursor: grabbing;
}

.menu-mgr-row-grip {
    width: 1.25rem;
    min-height: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--theme-text-muted);
    cursor: grab;
    flex-shrink: 0;
    user-select: none;
}

.menu-mgr-row:hover .menu-mgr-row-grip {
    color: var(--theme-text);
}

.menu-mgr-tree.readonly .menu-mgr-row-grip {
    visibility: hidden;
}

/* -- Tree view (Menu Manager revamp) ---------------------------------- */

.menu-mgr-tree {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.menu-mgr-tree.readonly .menu-mgr-row {
    opacity: 0.85;
}

.menu-mgr-node {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.menu-mgr-node.dragging .menu-mgr-row {
    opacity: 0.4;
}

/* Headers stand out a bit - subtle emphasis so the tree shape reads
   at a glance without shouting. */
.menu-mgr-row.row-header {
    background-color: var(--theme-background-subtle);
    border-color: var(--theme-border);
}

.menu-mgr-row.row-header .menu-mgr-row-name {
    font-weight: 700;
    letter-spacing: 0.01em;
}

/* Indented child strip - left connector line visually links children to
   their parent. The 1rem left margin matches grip+icon width so children
   align under the parent's label. */
.menu-mgr-children {
    margin-left: 1.75rem;
    padding-left: 0.75rem;
    border-left: 2px solid var(--theme-border-subtle);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.menu-mgr-node.depth-1 .menu-mgr-row {
    background-color: var(--theme-background);
}

.menu-mgr-empty-header {
    padding: 0.375rem 0.75rem;
    color: var(--theme-text-muted);
    font-size: var(--theme-font-size-xs);
    font-style: italic;
    background-color: var(--theme-background-subtle);
    border: 1px dashed var(--theme-border-subtle);
    border-radius: var(--theme-radius);
}

/* -- Chevron (expand/collapse) ---------------------------------------- */

.menu-mgr-chevron {
    border: 0;
    background: transparent;
    color: var(--theme-text-muted);
    padding: 0;
    width: 1rem;
    height: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.15s ease, color 0.15s ease;
}

.menu-mgr-chevron:hover { color: var(--theme-primary); }

.menu-mgr-chevron.expanded { transform: rotate(90deg); }

/* -- Drop indicators -------------------------------------------------- */
/* Three possible zones per row - visualized by an accent line above
   (before), an accent line below (after), or a ring around the whole
   row (into = nest as child). */

.menu-mgr-row.drag-over-before {
    box-shadow: 0 -3px 0 0 var(--theme-primary);
    border-top-color: var(--theme-primary);
}

.menu-mgr-row.drag-over-after {
    box-shadow: 0 3px 0 0 var(--theme-primary);
    border-bottom-color: var(--theme-primary);
}

.menu-mgr-row.drag-over-into {
    outline: 2px solid var(--theme-primary);
    outline-offset: -2px;
    background-color: var(--theme-primary-muted);
}

.menu-mgr-toplevel-drop {
    margin-top: 0.5rem;
    padding: 0.5rem 0.75rem;
    text-align: center;
    color: var(--theme-text-muted);
    font-size: var(--theme-font-size-sm);
    background-color: var(--theme-background);
    border: 1px dashed var(--theme-border-subtle);
    border-radius: var(--theme-radius);
    transition: var(--theme-transition);
}

.menu-mgr-toplevel-drop.active {
    color: var(--theme-primary);
    background-color: var(--theme-primary-muted);
    border-color: var(--theme-primary);
    border-style: solid;
}

/* -- Chips (row metadata badges) -------------------------------------- */

.menu-mgr-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.125rem;
    padding: 0.0625rem 0.375rem;
    background-color: var(--theme-background-subtle);
    color: var(--theme-text-muted);
    border: 1px solid var(--theme-border-subtle);
    border-radius: var(--theme-radius);
    font-size: var(--theme-font-size-xs);
    font-weight: 500;
    line-height: 1.25;
}

.menu-mgr-chip-channel   { border-color: var(--theme-primary); color: var(--theme-primary); }
.menu-mgr-chip-home      { border-color: var(--theme-accent, var(--theme-primary)); color: var(--theme-accent, var(--theme-primary)); }
.menu-mgr-chip-hidden    { border-color: var(--theme-warning, var(--theme-text-muted)); color: var(--theme-warning, var(--theme-text-muted)); }
.menu-mgr-chip-api       { border-color: var(--theme-success, var(--theme-text-muted)); color: var(--theme-success, var(--theme-text-muted)); }

.menu-mgr-type-badge.menu-mgr-type-header {
    background-color: var(--theme-accent-muted, var(--theme-primary-muted));
    color: var(--theme-accent, var(--theme-primary));
}

/* -- Quick-add header inline row -------------------------------------- */

.menu-mgr-quick-row {
    margin-bottom: 0.5rem;
}

.menu-mgr-quick-toggle {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.625rem;
}

.menu-mgr-quick-form {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.5rem;
    background-color: var(--theme-background);
    border: 1px solid var(--theme-primary);
    border-radius: var(--theme-radius);
    animation: menu-mgr-quick-in 0.15s ease-out;
}

.menu-mgr-quick-form input {
    flex: 1 1 auto;
    min-width: 0;
}

.menu-mgr-quick-icon {
    color: var(--theme-primary);
    font-size: 1.1rem;
    flex-shrink: 0;
}

@keyframes menu-mgr-quick-in {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* -- Add-child button tints with the primary hue so it reads as an
   additive action instead of sitting visually next to Edit/Delete. */

.menu-mgr-add-child {
    color: var(--theme-success, var(--theme-primary));
}

.menu-mgr-add-child:hover {
    color: var(--theme-primary);
}

/* -- Icon picker (Phase 2c.6) ---------------------------------------- */

.menu-mgr-icon-browse {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.25rem 0.5rem;
}

.icon-picker-modal {
    max-width: 44rem;
    width: 92vw;
}

.icon-picker-body {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: 22rem;
}

.icon-picker-search {
    position: relative;
    display: flex;
    align-items: center;
}

.icon-picker-search .bi-search {
    position: absolute;
    left: 0.5rem;
    color: var(--theme-text-muted);
}

.icon-picker-search input {
    padding-left: 1.75rem;
}

.icon-picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(6rem, 1fr));
    gap: 0.375rem;
    overflow-y: auto;
    max-height: 26rem;
    padding: 0.25rem;
}

.icon-picker-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.5rem 0.25rem;
    background-color: var(--theme-background);
    border: 1px solid var(--theme-border-subtle);
    border-radius: var(--theme-radius);
    color: var(--theme-text);
    cursor: pointer;
    transition: var(--theme-transition);
}

.icon-picker-cell i {
    font-size: 1.375rem;
    color: var(--theme-primary);
}

.icon-picker-cell:hover,
.icon-picker-cell.hovered {
    background-color: var(--theme-primary-muted);
    border-color: var(--theme-primary);
}

.icon-picker-cell-label {
    font-size: var(--theme-font-size-xs);
    color: var(--theme-text-muted);
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.icon-picker-cell:hover .icon-picker-cell-label {
    color: var(--theme-text);
}

.icon-picker-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    text-align: center;
    color: var(--theme-text-muted);
}

.icon-picker-empty i {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

/* -- A conversation menu item's FACE (MENU.md, type 8 - MenuWorkflowFace) ----------------------------------------------------
   Two pieces, both owned here: the face picker in the edit dialog (the shared .wf-choice cards, three across, stacked on a
   narrow dialog) and the launch page's face mode (/workflows/launch/{id}?face=concierge|rcs) - an APP page that fills the
   sheet: a header naming the conversation and the face, then the face's own page in a full-height frame. Token-only. */

.mid-face-group {
    grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
}

.mid-face-group .wf-choice {
    min-height: 100%;
}

.mid-face-note {
    display: flex;
    align-items: flex-start;
    gap: 0.375rem;
    margin-top: 0.5rem;
    font-size: var(--theme-font-size-xs);
    color: var(--theme-text-muted);
}

.mf-page {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    min-width: 0;
    gap: 0.75rem;
    overflow: hidden;
}

.mf-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 1rem;
    flex: none;
}

.mf-head-text {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
}

.mf-face-pill {
    display: inline-flex;
    align-items: center;
    align-self: flex-start;
    gap: 0.375rem;
    padding: 0.125rem 0.625rem;
    border-radius: var(--wf-radius-pill);
    background: var(--wf-primary-soft);
    color: var(--wf-primary-ink);
    font-size: 12px;
    font-weight: 600;
}

.mf-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 650;
    line-height: 1.25;
    color: var(--theme-text-emphasis);
    overflow-wrap: anywhere;
}

.mf-head-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.mf-code {
    max-width: 10rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* The face fills the rest of the sheet - a stage on the card fill, its own corners and hairline. */
.mf-stage {
    display: flex;
    flex: 1;
    min-height: 0;
    border: 1px solid var(--wf-line);
    border-radius: var(--wf-radius-lg);
    background: var(--wf-card);
    box-shadow: var(--wf-elev-1);
    overflow: hidden;
}

.mf-frame {
    display: block;
    flex: 1;
    width: 100%;
    height: 100%;
    border: 0;
    background: transparent;
}

.mf-foot {
    flex: none;
    margin: 0;
    font-size: var(--theme-font-size-xs);
    color: var(--theme-text-muted);
}

/* Loading - three soft dots on the stage, never a bare spinner in an empty field. */
.mf-stage-wait,
.mf-stage-note {
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.mf-wait {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    color: var(--theme-text-secondary);
    font-size: var(--theme-font-size-sm);
}

.mf-wait-dots {
    display: inline-flex;
    gap: 0.375rem;
}

.mf-wait-dots > span {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--wf-primary-ink);
    opacity: 0.35;
    animation: mf-wait-pulse 1.2s ease-in-out infinite;
}

.mf-wait-dots > span:nth-child(2) { animation-delay: 0.15s; }
.mf-wait-dots > span:nth-child(3) { animation-delay: 0.3s; }

@keyframes mf-wait-pulse {
    0%, 100% { opacity: 0.35; transform: translateY(0); }
    50% { opacity: 1; transform: translateY(-3px); }
}

@media (prefers-reduced-motion: reduce) {
    .mf-wait-dots > span { animation: none; opacity: 0.7; }
}

/* A refusal - one calm card: why, then the web form (the one primary) and home. */
.mf-note {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    max-width: 28rem;
    text-align: center;
}

.mf-note-icon {
    display: grid;
    place-items: center;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    background: var(--wf-primary-soft);
    color: var(--wf-primary-ink);
    font-size: 1.375rem;
}

.mf-note-title {
    margin: 0.25rem 0 0;
    font-size: 1.0625rem;
    font-weight: 650;
    color: var(--theme-text-emphasis);
}

.mf-note-text {
    margin: 0;
    color: var(--theme-text-secondary);
    font-size: var(--theme-font-size-sm);
    line-height: 1.5;
}

.mf-note-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

/* A phone at a booth (375 px): the header stacks, the actions take their own row, the face keeps the screen. */
@media (max-width: 30rem) {
    .mf-head { align-items: flex-start; }
    .mf-head-actions { width: 100%; }
    .mf-head-actions .btn { flex: 1; justify-content: center; }
    .mf-title { font-size: 1.0625rem; }
    .mf-stage { border-radius: var(--wf-radius-md); }
}
