/* ============================================================================
   User menu
   The header auth control, in the style first used on the Frontier PDM app
   (static/growthguru/pdm/index.html).

   Exactly one control is visible at a time:
     signed out — a single primary "Sign In" button. No ghost avatar, no
                  "Guest" label.
     signed in  — a pill trigger (avatar + name + caret) that opens a dropdown
                  holding Account settings, any page-specific items, and
                  Sign out.

   Rendered by static/js/auth/user-menu.js.
   ============================================================================ */

/* Every colour resolves through a chain, so this drops into either variable
   vocabulary in the codebase without per-site overrides: the app themes
   (--text-color / --border-color / --accent-color), GrowthCanvas
   (--text / --line / --accent), then a literal.

   --accent is checked BEFORE --accent-color: only a site that means it declares
   --accent, whereas --accent-color always has a generic value from theme-base,
   so preferring it would paint GrowthCanvas's orange header blue.

   A site whose brand colour lives somewhere else entirely can point the menu at
   it by overriding --um-accent on .um — see essentialgovernance-theme.css. */
.um {
    --um-text:        var(--text-color, var(--text, #1f2937));
    --um-muted:       var(--text-secondary, var(--muted, #6b7280));
    --um-line:        var(--border-color, var(--line, #e5e7eb));
    --um-accent:      var(--accent, var(--accent-color, #7c3aed));
    --um-accent-dark: var(--accent-color-dark, color-mix(in srgb, var(--um-accent) 82%, #000));
    --um-surface:     var(--bg-secondary, var(--card, #ffffff));
    --um-pill:        var(--bg-tertiary, var(--um-surface));
    --um-hover:       var(--bg-hover, color-mix(in srgb, var(--um-text) 8%, transparent));
    --um-inv:         var(--text-color-inv, #ffffff);
    --um-danger:      var(--danger-color, var(--bad, #dc2626));

    position: relative;
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
}

/* ── Signed-in trigger ──────────────────────────────────────────────────── */
.um-trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px 4px 4px;
    border: 1px solid var(--um-line);
    border-radius: 999px;
    background: var(--um-pill);
    color: var(--um-text);
    font: inherit;
    line-height: 1;
    cursor: pointer;
    transition: background .18s ease, border-color .18s ease;
}

.um-trigger:hover { background: var(--um-hover); }

.um-trigger:focus-visible {
    outline: 2px solid var(--um-accent);
    outline-offset: 2px;
}

.um-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--um-accent);
    color: var(--um-inv);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    overflow: hidden;
}

.um-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.um-name {
    max-width: 160px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 13px;
    font-weight: 600;
    color: var(--um-text);
}

.um-caret {
    flex: 0 0 auto;
    font-size: 11px;
    color: var(--um-muted);
    transition: transform .18s ease;
}

.um.is-open .um-caret { transform: rotate(180deg); }

/* ── Dropdown ───────────────────────────────────────────────────────────── */
.um-menu {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 200;
    min-width: 200px;
    padding: 6px;
    border: 1px solid var(--um-line);
    border-radius: 10px;
    background: var(--um-surface);
    box-shadow: 0 8px 24px color-mix(in srgb, var(--um-text) 22%, transparent);
}

.um.is-open .um-menu { display: block; }

.um-item {
    display: block;
    width: 100%;
    padding: 8px 10px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--um-text);
    font: inherit;
    font-size: 13px;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.um-item:hover,
.um-item:focus-visible {
    background: color-mix(in srgb, var(--um-text) 8%, transparent);
    color: var(--um-text);
    outline: none;
}

.um-item-danger { color: var(--um-danger); }
.um-item-danger:hover,
.um-item-danger:focus-visible { color: var(--um-danger); }

.um-sep {
    height: 1px;
    margin: 6px 4px;
    background: var(--um-line);
}

/* ── Signed-out button ──────────────────────────────────────────────────── */
.um-signin {
    display: inline-flex;
    align-items: center;
    padding: 8px 16px;
    border: 1px solid var(--um-accent);
    border-radius: 8px;
    background: var(--um-accent);
    color: var(--um-inv);
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background .18s ease, border-color .18s ease;
}

.um-signin:hover,
.um-signin:focus-visible {
    background: var(--um-accent-dark);
    border-color: var(--um-accent-dark);
    color: var(--um-inv);
}

/* The page's original auth button, kept in the DOM as a hidden controller: it
   still owns the click handler and is still the target of authActionBtn.click().
   !important because pages assign to its style.display directly. */
.um-proxy { display: none !important; }

/* These rules give the elements a display value, which beats the browser's own
   [hidden] rule — so [hidden] has to be restated for each of them. Without this
   the header would show both controls at once. */
.um-trigger[hidden],
.um-signin[hidden],
.um-item[hidden],
.um-menu[hidden] { display: none; }

@media (max-width: 600px) {
    .um-name { display: none; }
    .um-trigger { padding: 4px; }
}

@media (prefers-reduced-motion: reduce) {
    .um-trigger, .um-caret, .um-signin { transition: none; }
}
