/* ============================================================================
   profile-button.css — dedicated profile button + popover
   ============================================================================
   Renders next to the messages/invitations buttons inside .header-tray--icons.
   Clearly signals signed-in vs signed-out at a glance via:
     - an ambient status dot (green = signed in, muted = signed out, amber
       pulse = authenticating, red = error)
     - an avatar circle (photo or initials) when signed in, a person glyph
       when signed out.

   Also renders a small popover below the button with identity details and the
   sign-in / sign-out action so it feels like a dedicated surface, not a
   tooltip.
   ============================================================================ */

.profile-button-mount {
    position: relative;
    display: inline-flex;
    align-items: stretch;
}

/* Standalone variant — used when the button is NOT inside a .header-tray.
   Gives the button its own glassy pill so it reads as a first-class header
   control (used by atlas-shell which doesn't load header-cluster.css). */
.profile-button-mount--standalone {
    height: 36px;
}

.profile-button-mount--standalone .profile-button {
    border: 1px solid var(--line, rgba(255, 255, 255, 0.12));
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.04);
    -webkit-backdrop-filter: blur(14px) saturate(1.2);
    backdrop-filter: blur(14px) saturate(1.2);
}

.profile-button {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 100%;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    color: var(--text-secondary, #c8d5ef);
    cursor: pointer;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    transition: background 200ms ease, color 200ms ease;
}

.profile-button:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text, #f0f0f0);
}

.profile-button[aria-expanded="true"] {
    background: rgba(88, 215, 196, 0.12);
    color: var(--accent-2, #58d7c4);
}

.profile-button[data-state="signed-in"] {
    color: var(--accent-2, #58d7c4);
}

.profile-button[data-state="error"] {
    color: var(--danger, #ff7a7a);
}

/* ----- avatar disc -------------------------------------------------------- */

.profile-button__avatar {
    position: relative;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--text, #f0f0f0);
    background: linear-gradient(135deg, rgba(88, 215, 196, 0.36), rgba(139, 156, 255, 0.44));
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
    overflow: hidden;
    line-height: 1;
    user-select: none;
}

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

.profile-button__glyph {
    width: 22px;
    height: 22px;
    color: currentColor;
    opacity: 0.9;
}

/* ----- ambient status dot -------------------------------------------------- */

.profile-button__dot {
    position: absolute;
    right: 4px;
    bottom: 4px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--muted, #a7b3d0);
    box-shadow: 0 0 0 2px var(--bg-deep, #0b0f1c);
    transition: background 240ms ease, box-shadow 320ms ease;
    pointer-events: none;
}

.profile-button[data-state="signed-in"] .profile-button__dot {
    background: var(--success, #6ef0a8);
    box-shadow:
        0 0 0 2px var(--bg-deep, #0b0f1c),
        0 0 0 4px rgba(110, 240, 168, 0.18),
        0 0 8px rgba(110, 240, 168, 0.55);
}

.profile-button[data-state="authenticating"] .profile-button__dot {
    background: var(--accent-3, #f5b87a);
    animation: profile-dot-pulse 1.6s ease-in-out infinite;
}

.profile-button[data-state="error"] .profile-button__dot {
    background: var(--danger, #ff7a7a);
    box-shadow:
        0 0 0 2px var(--bg-deep, #0b0f1c),
        0 0 0 4px rgba(255, 122, 122, 0.18);
}

@keyframes profile-dot-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(0.78); opacity: 0.7; }
}

/* ----- popover ------------------------------------------------------------ */

.profile-popover {
    position: fixed;
    z-index: 1300;
    width: 280px;
    padding: 16px;
    border-radius: 16px;
    background: rgba(14, 20, 36, 0.96);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--text, #f0f0f0);
    box-shadow:
        0 24px 60px rgba(2, 5, 12, 0.6),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(20px) saturate(1.2);
    -webkit-backdrop-filter: blur(20px) saturate(1.2);
    display: flex;
    flex-direction: column;
    gap: 12px;
    font-size: 13px;
}

.profile-popover[hidden] { display: none; }

.profile-popover::before {
    content: "";
    position: absolute;
    top: -6px;
    right: 12px;
    width: 12px;
    height: 12px;
    background: inherit;
    border-left: 1px solid rgba(255, 255, 255, 0.12);
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    transform: rotate(45deg);
}

.profile-popover__head {
    display: flex;
    align-items: center;
    gap: 12px;
}

.profile-popover__avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: var(--text, #f0f0f0);
    background: linear-gradient(135deg, rgba(88, 215, 196, 0.4), rgba(139, 156, 255, 0.5));
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
    overflow: hidden;
    flex-shrink: 0;
}

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

.profile-popover__identity {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.profile-popover__label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-secondary, #c8d5ef);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.profile-popover__label::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--muted, #a7b3d0);
}

.profile-popover[data-state="signed-in"] .profile-popover__label {
    color: var(--success, #6ef0a8);
}

.profile-popover[data-state="signed-in"] .profile-popover__label::before {
    background: var(--success, #6ef0a8);
    box-shadow: 0 0 0 3px rgba(110, 240, 168, 0.18);
}

.profile-popover[data-state="error"] .profile-popover__label {
    color: var(--danger, #ff7a7a);
}

.profile-popover[data-state="error"] .profile-popover__label::before {
    background: var(--danger, #ff7a7a);
}

.profile-popover__name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text, #f0f0f0);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.profile-popover__meta {
    font-size: 11px;
    color: var(--text-secondary, #c8d5ef);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.profile-popover__body {
    font-size: 12px;
    color: var(--text-secondary, #c8d5ef);
    line-height: 1.5;
}

.profile-popover__error {
    font-size: 12px;
    color: var(--danger, #ff7a7a);
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(255, 122, 122, 0.08);
    border: 1px solid rgba(255, 122, 122, 0.25);
}

.profile-popover__actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.profile-popover__action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 34px;
    padding: 0 12px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--text, #f0f0f0);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.profile-popover__action:hover:not([disabled]) {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.22);
}

.profile-popover__action[disabled] {
    opacity: 0.55;
    cursor: default;
}

.profile-popover__action--primary {
    background: linear-gradient(180deg, rgba(88, 215, 196, 0.22), rgba(88, 215, 196, 0.12));
    color: var(--accent-2, #58d7c4);
    border-color: rgba(88, 215, 196, 0.35);
}

.profile-popover__action--primary:hover:not([disabled]) {
    background: linear-gradient(180deg, rgba(88, 215, 196, 0.3), rgba(88, 215, 196, 0.16));
    border-color: rgba(88, 215, 196, 0.55);
}

.profile-popover__action--danger {
    color: var(--danger, #ff7a7a);
    border-color: rgba(255, 122, 122, 0.3);
}

.profile-popover__action--danger:hover:not([disabled]) {
    background: rgba(255, 122, 122, 0.1);
    border-color: rgba(255, 122, 122, 0.5);
}

.profile-popover__provider-icon {
    width: 14px;
    height: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.profile-popover__provider-icon svg {
    width: 100%;
    height: 100%;
}

.profile-popover__footnote {
    font-size: 10px;
    color: var(--muted, #a7b3d0);
    line-height: 1.4;
}

/* ----- not-configured placeholder ----------------------------------------- */

.profile-button[data-state="not-configured"] {
    opacity: 0.6;
    cursor: help;
}

/* Light-theme rebalance */
:root[data-theme="light"] .profile-popover {
    background: rgba(250, 249, 247, 0.98);
    border-color: rgba(30, 28, 24, 0.12);
    color: #1b1a17;
    box-shadow: 0 24px 60px rgba(30, 28, 24, 0.18);
}

:root[data-theme="light"] .profile-popover::before {
    border-left-color: rgba(30, 28, 24, 0.12);
    border-top-color: rgba(30, 28, 24, 0.12);
}

:root[data-theme="light"] .profile-popover__name { color: #1b1a17; }
:root[data-theme="light"] .profile-popover__meta,
:root[data-theme="light"] .profile-popover__body,
:root[data-theme="light"] .profile-popover__footnote {
    color: #4a4740;
}

:root[data-theme="light"] .profile-popover__action {
    background: rgba(30, 28, 24, 0.04);
    border-color: rgba(30, 28, 24, 0.14);
    color: #1b1a17;
}

:root[data-theme="light"] .profile-popover__action:hover:not([disabled]) {
    background: rgba(30, 28, 24, 0.08);
    border-color: rgba(30, 28, 24, 0.28);
}

@media (prefers-reduced-motion: reduce) {
    .profile-button[data-state="authenticating"] .profile-button__dot { animation: none; }
}
