/* =========================================================================
   toast-messenger.css — Floating chat toast popup windows
   ========================================================================= */

/* ── container ───────────────────────────────────────────────────────────── */
.toast-messenger-container {
    position: fixed;
    bottom: 0;
    right: 0;
    z-index: 9000;
    pointer-events: none;
    display: flex;
    flex-direction: row-reverse;
    align-items: flex-end;
    gap: 12px;
    padding-right: 20px;
}

/* ── chat window ─────────────────────────────────────────────────────────── */
.toast-chat-window {
    pointer-events: all;
    width: 320px;
    max-height: 730px;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary, #111);
    border: 1px solid rgba(168, 85, 247, 0.22);
    border-bottom: none;
    border-radius: 14px 14px 0 0;
    box-shadow:
        0 -6px 40px rgba(0, 0, 0, 0.6),
        0 0 0 1px rgba(168, 85, 247, 0.06) inset;
    backdrop-filter: blur(20px) saturate(1.4);
    -webkit-backdrop-filter: blur(20px) saturate(1.4);
    opacity: 0;
    transform: translateY(24px) scale(0.97);
    transition:
        opacity 240ms cubic-bezier(0.34, 1.56, 0.64, 1),
        transform 240ms cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
}
.toast-chat-window.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}
.toast-chat-window.minimized {
    display: none;
}

/* ── minimised chat — floating 32×32 avatar icon ─────────────────────────── */
@keyframes mini-avatar-pulse {
    0%   { border-color: rgba(168, 85, 247, 0.55); box-shadow: 0 4px 14px rgba(0,0,0,0.5),        0 0 0 2px rgba(168,85,247,0.15); }
    40%  { border-color: rgba(249, 115, 22, 1);    box-shadow: 0 4px 22px rgba(249,115,22,0.65),  0 0 0 3px rgba(249,115,22,0.45); }
    100% { border-color: rgba(168, 85, 247, 0.55); box-shadow: 0 4px 14px rgba(0,0,0,0.5),        0 0 0 2px rgba(168,85,247,0.15); }
}

.toast-mini-avatar {
    position: fixed;
    z-index: 9001;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid rgba(168, 85, 247, 0.55);
    background: var(--bg-secondary, #111);
    padding: 0;
    cursor: grab;
    touch-action: none;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5), 0 0 0 2px rgba(168, 85, 247, 0.15);
    transition: transform 150ms ease, box-shadow 150ms ease, border-color 150ms ease;
    overflow: visible;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: all;
}
.toast-mini-avatar:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6), 0 0 0 3px rgba(168, 85, 247, 0.35);
}
.toast-mini-avatar.dragging {
    cursor: grabbing;
    transform: scale(1.06);
}
.toast-mini-avatar.pulsing {
    animation: mini-avatar-pulse 700ms ease-out 1 forwards;
}

.mini-avatar-img-wrap {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    /* Ensure UIComponents cr-user-avatar fills the wrap */
    position: relative;
}
.mini-avatar-img-wrap .cr-user-avatar,
.mini-avatar-img-wrap .cr-user-avatar-sm {
    width: 28px !important;
    height: 28px !important;
}
.mini-avatar-img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}
.mini-avatar-initial {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent-muted, rgba(168, 85, 247, 0.2));
    color: var(--accent, #a855f7);
    font-size: 0.72rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.toast-mini-avatar-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 16px;
    height: 16px;
    padding: 0 3px;
    border-radius: 8px;
    background: rgba(249, 115, 22, 0.95);
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    border: 1.5px solid var(--bg-primary, #0f0f0f);
    line-height: 1;
}
.toast-mini-avatar-badge.hidden { display: none; }

/* ── header ──────────────────────────────────────────────────────────────── */
@keyframes chat-header-pulse {
    0%, 100% { background: var(--bg-tertiary, #1a1a1a); }
    50%       { background: rgba(249, 115, 22, 0.28); }
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.75rem;
    background: var(--bg-tertiary, #1a1a1a);
    border-bottom: 1px solid rgba(168, 85, 247, 0.14);
    cursor: pointer;
    user-select: none;
    flex-shrink: 0;
    transition: background 300ms ease;
}
.chat-header.chat-header-pulsing {
    animation: chat-header-pulse 1.6s ease-in-out infinite;
}

.chat-header-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    flex: 1;
}
.chat-avatar-wrap {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
}
.chat-avatar-initial {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--accent-muted, rgba(168, 85, 247, 0.2));
    color: var(--accent, #a855f7);
    font-size: 0.8rem;
    font-weight: 700;
}
.chat-header-info {
    min-width: 0;
}
.chat-header-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary, #f0f0f0);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-header-handle {
    font-size: 0.72rem;
    color: var(--text-secondary, #999);
}
.chat-unread-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: rgba(249, 115, 22, 0.9);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    flex-shrink: 0;
    margin-left: 6px;
    transition: opacity 150ms ease;
}
.chat-unread-badge.hidden { display: none; }

.chat-header-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}
.chat-action-btn {
    background: none;
    border: none;
    color: var(--text-secondary, #aaa);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 3px 7px;
    border-radius: 5px;
    transition: color 150ms, background 150ms;
}
.chat-action-btn:hover {
    color: var(--text-primary, #f0f0f0);
    background: rgba(168, 85, 247, 0.14);
}

/* ── message area ────────────────────────────────────────────────────────── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.75rem 0.75rem 0.25rem;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--bg-primary, #0f0f0f);
    scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 3px; }
.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(168, 85, 247, 0.2);
    border-radius: 2px;
}

.chat-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 2rem 1rem;
    color: var(--text-secondary, #666);
    text-align: center;
    flex: 1;
}
.chat-empty-state i { font-size: 1.6rem; color: rgba(168, 85, 247, 0.3); }
.chat-empty-state p { font-size: 0.82rem; margin: 0; }

/* ── message rows inside toast ───────────────────────────────────────────── */
.chat-messages .message {
    display: flex;
    align-items: flex-end;
    gap: 0.4rem;
    margin-bottom: 0;
    max-width: 100%;
}
.chat-messages .message.msg-last,
.chat-messages .message.msg-solo {
    margin-bottom: 8px;
}
.chat-messages .message.own-message {
    flex-direction: row-reverse;
}
/* Received-run indent: keep bubbles left-aligned under the avatar */
.chat-messages .recv-message.no-avatar {
    padding-left: calc(32px + 0.4rem);
}

/* ── message bubbles ─────────────────────────────────────────────────────── */
.chat-messages .message-bubble {
    max-width: 78%;
    padding: 0.42rem 0.65rem;
    background: var(--bg-secondary, #1c1c1c);
    border-radius: 14px 14px 14px 4px;
    word-break: break-word;
}
.chat-messages .own-message .message-bubble {
    background: rgba(168, 85, 247, 0.22);
    border-radius: 14px 14px 4px 14px;
}

/* ── bubble border-radius per position in same-sender run ───────────────── */
/* recv (pivot = left) — solo inherits the base rule above */
.chat-messages .recv-message.msg-first .message-bubble { border-radius: 4px  14px 14px 14px; }
.chat-messages .recv-message.msg-mid   .message-bubble { border-radius: 4px  14px 14px 4px; }
.chat-messages .recv-message.msg-last  .message-bubble { border-radius: 4px  14px 14px 4px; }
/* own (pivot = right):
   solo = full 14px all corners
   top-right  = 0 unless it is the first bubble in the run  (14px when first/solo)
   bottom-right= 0 unless it is the last  bubble in the run (14px when solo)      */
.chat-messages .own-message.msg-solo   .message-bubble { border-radius: 14px 14px 14px 14px; }
.chat-messages .own-message.msg-first  .message-bubble { border-radius: 14px 14px  0px 14px; }
.chat-messages .own-message.msg-mid    .message-bubble { border-radius: 14px  0px  0px 14px; }
.chat-messages .own-message.msg-last   .message-bubble { border-radius: 14px  0px  4px 14px; }

.chat-messages .message-content {
    font-size: 0.86rem;
    color: var(--text-primary, #f0f0f0);
    line-height: 1.45;
}
.chat-messages .message-header {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--accent, #a855f7);
    margin-bottom: 2px;
}
.chat-messages .message-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.35rem;
    margin-top: 3px;
}
.chat-messages .message-time {
    font-size: 0.62rem;
    color: var(--text-secondary, #888);
    white-space: nowrap;
}

/* ── status icon colours (toast mirrors messenger.css) ───────────────────── */
.chat-messages .message-status { font-size: 0.62rem; display: inline-flex; align-items: center; }
.chat-messages .msg-status--pending   { color: var(--text-secondary, #888); }
.chat-messages .msg-status--sent      { color: var(--text-secondary, #888); }
.chat-messages .msg-status--delivered { color: var(--text-secondary, #aaa); }
.chat-messages .msg-status--read      { color: var(--accent, #a855f7); }

/* ── typing indicator atom inside toast windows ──────────────────────────── */
.toast-typing-indicator {
    padding: 0 0.75rem;
    background: var(--bg-primary, #0f0f0f);
    overflow: hidden;
    font-size: 0.72rem;
    flex-shrink: 0;
}
.toast-chat-window.minimized .toast-typing-indicator { display: none; }

/* ── composer area ───────────────────────────────────────────────────────── */
.chat-composer-wrap {
    border-top: 1px solid rgba(168, 85, 247, 0.12);
    padding: 0.45rem;
    background: var(--bg-secondary, #111);
    flex-shrink: 0;
}
.chat-composer-wrap .content-composer {
    border-radius: 9px;
    border: 1px solid rgba(168, 85, 247, 0.2);
    background: var(--bg-tertiary, #1a1a1a);
    min-height: 38px;
}
.chat-composer-wrap .composer-editor {
    min-height: 36px;
    max-height: 110px;
    font-size: 0.85rem;
    padding: 0.4rem 0.6rem;
}
.chat-composer-wrap .composer-toolbar { padding: 3px 6px; }
.chat-composer-wrap .composer-submit-btn { padding: 5px 10px; font-size: 0.8rem; }
