/**
 * VIPsAllowed — Profile chat drawer
 *
 * Themed LIGHT BY DEFAULT with dark overrides under body.fs-dark, deliberately.
 * Dark-only vars are what left profile post cards unreadable on tenant hubs: a
 * white surface kept its colour while bootstrap.dark.css painted the text light.
 * So the SURFACE moves with the theme here, and no text colour is pinned against
 * the theme's own utilities.
 */

.chat-drawer {
    --cd-surface: #ffffff;
    --cd-surface-2: #f4f6f8;
    --cd-border: #e3e7ec;
    --cd-text: #1a1a1a;
    --cd-muted: #6c757d;
    --cd-mine: var(--primary, #e0004d);
    --cd-mine-text: #ffffff;

    position: fixed;
    inset: 0;
    /* Above the cookie consent banner (z-index 9999, fixed to the bottom) —
       at any lower tier the banner sits directly over the composer and swallows
       clicks on the send button, so the drawer looks broken rather than covered. */
    z-index: 10050;
    display: none;
}

.chat-drawer.is-open {
    display: block;
}

.chat-drawer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.chat-drawer.is-open .chat-drawer-backdrop {
    opacity: 1;
}

.chat-drawer-panel {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    width: 400px;
    max-width: 100vw;
    background: var(--cd-surface);
    color: var(--cd-text);
    border-left: 1px solid var(--cd-border);
    box-shadow: -8px 0 28px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.24s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.chat-drawer.is-open .chat-drawer-panel {
    transform: translateX(0);
}

/* Header */
.chat-drawer-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--cd-border);
    flex: 0 0 auto;
}

.chat-drawer-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--cd-surface-2);
}

.chat-drawer-who {
    min-width: 0;
    flex: 1 1 auto;
    line-height: 1.2;
}

.chat-drawer-name {
    display: block;
    font-weight: 600;
    color: inherit;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-drawer-name:hover {
    text-decoration: underline;
    color: inherit;
}

.chat-drawer-handle {
    display: block;
    font-size: 0.8125rem;
    color: var(--cd-muted);
}

.chat-drawer-expand,
.chat-drawer-close {
    flex: 0 0 auto;
    background: none;
    border: none;
    padding: 6px;
    line-height: 0;
    border-radius: 50%;
    color: var(--cd-muted);
    font-size: 1.25rem;
    cursor: pointer;
}

.chat-drawer-expand:hover,
.chat-drawer-close:hover {
    background: var(--cd-surface-2);
    color: var(--cd-text);
}

/* Thread */
.chat-drawer-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 14px;
    background: var(--cd-surface-2);
}

.chat-drawer-thread {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.cd-msg {
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 16px;
    background: var(--cd-surface);
    border: 1px solid var(--cd-border);
    align-self: flex-start;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.cd-msg.is-mine {
    align-self: flex-end;
    background: var(--cd-mine);
    border-color: var(--cd-mine);
    color: var(--cd-mine-text);
}

.cd-msg-time {
    display: block;
    margin-top: 3px;
    font-size: 0.6875rem;
    opacity: 0.65;
}

.cd-msg.is-pending {
    opacity: 0.55;
}

.cd-msg.is-failed {
    border-color: #dc3545;
}

/* Empty / loading states */
.chat-drawer-state {
    text-align: center;
    color: var(--cd-muted);
    padding: 36px 12px;
}

.chat-drawer-empty ion-icon {
    font-size: 2.25rem;
    display: block;
    margin: 0 auto 8px;
}

.chat-drawer-spinner {
    width: 24px;
    height: 24px;
    margin: 0 auto;
    border: 2px solid var(--cd-border);
    border-top-color: var(--cd-muted);
    border-radius: 50%;
    animation: cd-spin 0.7s linear infinite;
}

@keyframes cd-spin {
    to { transform: rotate(360deg); }
}

/* Composer */
.chat-drawer-composer {
    flex: 0 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--cd-border);
    background: var(--cd-surface);
}

.chat-drawer-composer textarea {
    flex: 1 1 auto;
    resize: none;
    max-height: 120px;
    padding: 9px 12px;
    border-radius: 18px;
    border: 1px solid var(--cd-border);
    background: var(--cd-surface-2);
    color: inherit;
    font: inherit;
    outline: none;
}

.chat-drawer-composer textarea:focus {
    border-color: var(--cd-mine);
}

.chat-drawer-send {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    background: var(--cd-mine);
    color: #fff;
    font-size: 1.125rem;
    line-height: 0;
    cursor: pointer;
}

.chat-drawer-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Dark page chrome — move the SURFACE with the theme, same model as post.css */
body.fs-dark .chat-drawer,
body.hub-dark .chat-drawer {
    --cd-surface: var(--hub-surface, var(--card-bg, #16181d));
    --cd-surface-2: var(--hub-bg, #0f1115);
    --cd-border: var(--hub-surface-border, var(--border-color, #23262d));
    --cd-text: var(--body-color, #f2f4f7);
    --cd-muted: var(--text-muted, #9ca3af);
}

@media (max-width: 576px) {
    .chat-drawer-panel {
        width: 100%;
        border-left: none;
    }
}
