/* ============================================================
   Popover Manager — Unified anchored popover for single-control
   bulk actions and pickers across all table views.

   Base chrome shared with .popover, .user-multi-select-popover,
   .contract-multi-select-popover, .team-assignment-popover. All four use
   the same radius, shadow, and @keyframes popoverAppear animation.
   ============================================================ */

.popover-manager {
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-primary, #e2e8f0);
    border-radius: 12px;
    box-shadow:
        0 1px 2px rgba(0, 0, 0, 0.04),
        0 12px 32px -8px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: min(520px, calc(100vh - 32px));
    box-sizing: border-box;
    font-size: 0.8125rem;
    color: var(--text-primary, #1e293b);
    animation: popoverAppear 140ms cubic-bezier(0.2, 0, 0, 1);
    transform-origin: top left;
}

/* Keyframes are also defined in crm/leads.css and projects/projects.css —
   declared here too so bulk-drawer popovers animate without depending on
   page-level CSS load order. */
@keyframes popoverAppear {
    from { opacity: 0; transform: translateY(-4px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.popover-manager-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-primary, #e2e8f0);
    background: var(--bg-primary, #fff);
    flex-shrink: 0;
}

.popover-manager-title {
    font-weight: 600;
    font-size: 0.8125rem;
    letter-spacing: -0.005em;
    color: var(--text-primary, #1e293b);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.popover-manager-close {
    border: none;
    background: none;
    color: var(--text-muted, #9ca3af);
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    flex-shrink: 0;
    transition: background 120ms ease, color 120ms ease;
}

.popover-manager-close:hover {
    background: var(--bg-tertiary, #f1f5f9);
    color: var(--text-primary, #1e293b);
}

.popover-manager-close:focus-visible {
    outline: 2px solid rgba(var(--bg-primary-rgb, 99, 102, 241), 0.4);
    outline-offset: 1px;
}

.popover-manager-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 12px 14px;
    scrollbar-width: thin;
    scrollbar-color: var(--border-secondary, #d1d5db) transparent;
}

.popover-manager-option {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: start;
    cursor: pointer;
}

.popover-manager-option:hover,
.popover-manager-option:focus-visible,
.popover-manager-option.selected {
    background: var(--bg-button-secondary);
}

.popover-manager-option:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* openDatePicker() — single native date field */
.popover-date-input {
    width: 100%;
    padding: 8px 10px;
    font-size: 0.875rem;
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md, 8px);
    background: var(--bg-primary);
    color: var(--text-primary);
    outline: none;
}

.popover-date-input:focus {
    border-color: var(--bg-primary-color);
}

.popover-manager-body::-webkit-scrollbar { width: 8px; }
.popover-manager-body::-webkit-scrollbar-track { background: transparent; }
.popover-manager-body::-webkit-scrollbar-thumb {
    background: var(--border-secondary, #d1d5db);
    border-radius: 4px;
    border: 2px solid var(--bg-primary, #fff);
}

/* Body content conventions — legacy drawer bodies already wrap their own <p>
   and inline <select>; these defaults keep them readable inside the smaller
   popover. */

.popover-manager-body p {
    margin: 0 0 10px;
    color: var(--text-secondary, #64748b);
    font-size: 0.8125rem;
    line-height: 1.45;
}

.popover-manager-body p:last-child {
    margin-bottom: 0;
}

.popover-manager-body p strong {
    color: var(--text-primary, #1e293b);
    font-weight: 600;
}

.popover-manager-body .form-control,
.popover-manager-body select,
.popover-manager-body input[type="text"],
.popover-manager-body input[type="number"],
.popover-manager-body input[type="search"] {
    width: 100%;
    box-sizing: border-box;
    padding: 7px 10px;
    border: 1px solid var(--border-primary, #e2e8f0);
    border-radius: 8px;
    font-size: 0.8125rem;
    /* background-color: var(--input-bg, #fff); */
    color: var(--text-primary, #1e293b);
    transition: border-color 120ms ease, box-shadow 120ms ease;
}

.popover-manager-body .form-control:focus,
.popover-manager-body select:focus,
.popover-manager-body input:focus {
    outline: none;
    border-color: var(--bg-primary-color, #6366f1);
    box-shadow: 0 0 0 3px rgba(var(--bg-primary-rgb, 99, 102, 241), 0.12);
}

.popover-manager-body select[multiple] {
    min-height: 180px;
    padding: 6px;
}

.popover-manager-body label {
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-secondary, #64748b);
    margin-bottom: 6px;
}

.popover-manager-body .form-group {
    margin-bottom: 12px;
}

.popover-manager-body .form-group:last-child {
    margin-bottom: 0;
}

/* Footer */
.popover-manager-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid var(--border-primary, #e2e8f0);
    background: var(--bg-secondary, #f8fafc);
    flex-shrink: 0;
}

.popover-manager-footer .btn {
    font-size: 0.8125rem;
    padding: 6px 12px;
}

/* Mobile — full-width sheet-style popover when viewport is narrow */
@media (max-width: 480px) {
    .popover-manager,
    .popover,
    .user-multi-select-popover,
    .contract-multi-select-popover,
    .team-assignment-popover {
        width: calc(100vw - 16px) !important;
        max-width: none;
    }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
    .popover-manager,
    .popover,
    .user-multi-select-popover,
    .contract-multi-select-popover,
    .team-assignment-popover {
        animation: none;
    }
}

/* ============================================================
   Async (server-paged) multi-select — openAsyncMultiSelect()
   Shares .user-multi-select-popover chrome; adds the two-line option
   rows, the status line and the "Load more" affordance. Rows arrive one
   page at a time, so the popover never renders a whole address book.
   ============================================================ */

.popover-async-multi .user-multi-options {
    min-height: 140px;
}

.popover-async-multi .user-multi-option {
    align-items: flex-start;
}

.popover-async-multi .user-multi-option input[type="checkbox"] {
    margin-top: 3px;
}

.popover-async-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
    flex: 1;
}

.popover-async-label,
.popover-async-meta {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.popover-async-meta {
    font-size: 0.75rem;
    color: var(--text-muted, #9ca3af);
    font-weight: 400;
}

.popover-async-status {
    padding: 6px 12px;
    font-size: 0.75rem;
    color: var(--text-muted, #9ca3af);
    border-top: 1px solid var(--border-primary, #e2e8f0);
    flex-shrink: 0;
}

.popover-async-more {
    display: block;
    width: 100%;
    margin: 4px 0 2px;
    padding: 7px 10px;
    border: 1px dashed var(--border-primary, #e2e8f0);
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary, #475569);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 120ms ease, border-color 120ms ease;
}

.popover-async-more:hover {
    background: var(--bg-tertiary, #f1f5f9);
    border-color: var(--border-secondary, #d1d5db);
}

/* ============================================================
   Compact command menu — .qanvas-menu-popover
   ------------------------------------------------------------
   The Qanvas suite menu bar and its right-click menus are real
   application menus: 19 rows in File alone. They were rendering on the
   people-picker row (a 26px round avatar chip, and the description
   wrapped onto a SECOND line), which made those menus ~950px tall
   inside a 380px box — so every one of them scrolled internally
   (owner report 2026-08-29).

   This variant drops no row and no text. It puts icon + label +
   description + shortcut on ONE 26px line, turns the group separators
   into hairlines instead of 23px blank rows, and lets the menu use the
   full viewport height. Worst case (File, 19 rows / 6 groups) lands
   near 550px, so the whole menu opens at full height.
   ============================================================ */
.popover.qanvas-menu-popover {
    max-height: calc(100vh - 24px);
    min-width: 240px;
    border-radius: 10px;
}

.popover.qanvas-menu-popover .popover-lists {
    padding: 4px;
}

.popover.qanvas-menu-popover .popover-list {
    /* The base row is content-box, so its min-height and padding ADD. Border-box
       here makes 26px mean 26px. */
    box-sizing: border-box;
    overflow: hidden;
    flex-wrap: nowrap;
    gap: 0;
    min-height: 26px;
    padding: 3px 8px;
    border-radius: 6px;
    line-height: 1.3;
}

/* The circular avatar chip is a people-picker affordance; a command menu
   wants a plain leading glyph on the text baseline. */
.popover.qanvas-menu-popover .assign-option-avatar {
    width: 15px;
    height: 15px;
    margin-inline-end: 10px;
    background: none;
    border-radius: 0;
    color: var(--text-secondary, #6b7280);
    font-size: 0.75rem;
    font-weight: 400;
}

/* min-width: calc(100% - 50px) on the base row is what pushes the meta onto a
   second line. A menu row never wraps. The label is what the user reads, so it
   shrinks LAST — the outsized shrink factor on the description below makes the
   description give up its space first. Full text stays in the row's title. */
.popover.qanvas-menu-popover .assign-option-name {
    flex: 1 0 auto;
    /* Zero, not "small": flex-shrink is weighted by basis, so even a factor of
       100 on the description still bled ~1px off the label and lit an ellipsis
       on rows that fit ("New from template…", "Paste without formatting"). The
       description absorbs the overflow instead. max-width keeps a pathological
       label inside the row and ellipsizing rather than clipped. */
    flex-shrink: 0;
    min-width: 0;
    max-width: 100%;
    padding-inline-end: 12px;
}

.popover.qanvas-menu-popover .assign-option-meta,
.popover.qanvas-menu-popover .assign-option-kbd {
    padding-inline-start: 0;
    margin-top: 0;
    font-size: 0.6875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-muted, #9ca3af);
}

/* Description: absorbs the slack and ellipsizes before the label or the
   shortcut does (shrink factor is weighted by basis, so it needs to outweigh
   the label by a wide margin, not by one). */
.popover.qanvas-menu-popover .assign-option-meta {
    flex: 0 1 auto;
    flex-shrink: 100;
    min-width: 0;
    margin-inline-start: auto;
    text-align: end;
}

/* Shortcut: pinned right at its natural width, never truncated. */
.popover.qanvas-menu-popover .assign-option-kbd {
    flex: none;
    margin-inline-start: auto;
    padding-inline-start: 10px;
    font-variant-numeric: tabular-nums;
}

.popover.qanvas-menu-popover .assign-option-meta + .assign-option-kbd {
    margin-inline-start: 0;
}

/* Group separators arrive as empty .lead-assign-heading rows. A hairline, not
   a blank row — six groups gave the File menu ~140px of dead height. */
.popover.qanvas-menu-popover .lead-assign-heading,
.popover.qanvas-menu-popover .lead-assign-heading:not(:first-child) {
    height: 0;
    min-height: 0;
    padding: 0;
    margin: 4px 6px;
    border-top: 1px solid var(--border-primary, #e5e7eb);
}

.popover.qanvas-menu-popover .lead-assign-heading + .popover-list {
    margin-top: 0;
}

/* A leading separator (the Back row's divider is drawn by the row above it). */
.popover.qanvas-menu-popover .lead-assign-heading:first-child {
    display: none;
}

/* Flow's right-click menu owns its own markup (.qanvas-flow-context-menu in
   qanvas.css) but rides the same shell — a 20-row multi-select menu needs the
   same full-height allowance. */
.popover-manager.qanvas-flow-context-popover {
    max-height: calc(100vh - 24px);
}
