#composeConversation {
    overflow-y: auto;
    min-height: 0;
}
/* Only show vertical scrollbar for the user list, not the whole compose area */
.messaging-to-user-list-scroll {
    max-height: 200px;
    overflow-y: auto;
}
.messaging-compose-footer {
    position: sticky;
    bottom: 0;
    background: #fff;
    padding-bottom: 8px;
    z-index: 3;
}
.messaging-sidebar-header {
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 2;
    border-bottom: 1px solid #eee;
}
.chat-bubble-sent {
    background: var(--bs-info, #1976d2);
    color: var(--bs-card-foreground, #fff);
    border-radius: 16px 16px 4px 16px;
    padding: 10px 16px;
    margin-bottom: 6px;
    display: inline-block;
    max-width: 80%;
    word-break: break-word;
    box-shadow: 0 2px 8px rgba(25, 118, 210, 0.08);
}
.chat-bubble-received {
    background: var(--bs-card-bg-2, #f1f1f1);
    color: var(--bs-card-fore-2, #333);
    border-radius: 16px 16px 16px 4px;
    padding: 10px 16px;
    margin-bottom: 6px;
    display: inline-block;
    max-width: 80%;
    word-break: break-word;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.chat-time {
    font-size: 0.85em;
    color: #888;
    margin-left: 8px;
}
.messaging-sidebar {
    position: fixed;
    left: 0; /* fixed to left like a messenger */
    top: var(--bs-navbar-height, 56px); /* navbar height variable */
    width: 340px;
    min-width: 280px;
    max-width: 600px;
    height: calc(100vh - 56px);
    background: var(--bs-card-bg, #fff);
    border-right: 1px solid rgba(0,0,0,0.06); /* right border since it's on left */
    z-index: 900; /* lowered so navbar dropdowns and footer remain above */
    display: flex;
    flex-direction: column;
    overflow: auto;
    border-radius: 0 12px 12px 0;
    /* disable manual resize to match messenger fixed behavior */
    resize: none;
}
#messagingHistory {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding: 8px;
    max-height: 100%;
}
.messaging-sidebar-header {
    padding: 12px;
    font-weight: bold;
    background: #f7f7f7;
    border-bottom: 1px solid #eee;
}
#messagingSidebarUsers {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.user-row {
    padding: 8px;
    cursor: pointer;
    border-bottom: 1px solid #eee;
}
.user-row:hover {
    background: #e9f5ff;
}
.user-row.active {
    background: #d9f0ff;
    border-left: 3px solid #1976d2;
}
.messaging-chat {
    border-top: 1px solid #eee;
    background: #fafafa;
    padding: 8px;
    flex-shrink: 0;
}
#messagingChatBody {
    height: 220px;
    max-height: 40vh;
    overflow-y: auto;
    margin-bottom: 8px;
    background: var(--bs-card-bg, #fff);
    border: 1px solid rgba(0,0,0,0.04);
    padding: 8px;
}
.msg-sent {
    /* Message bubble for messages sent by current user */
    background: #1976d2;
    color: #fff;
    border-radius: 16px 16px 4px 16px;
    padding: 8px 12px;
    margin: 6px 0 6px auto; /* align right */
    display: inline-block;
    max-width: 85%;
    word-break: break-word;
    box-shadow: 0 2px 8px rgba(25, 118, 210, 0.08);
}
.msg-received {
    /* Message bubble for messages received */
    background: #f1f1f1;
    color: #222;
    border-radius: 16px 16px 16px 4px;
    padding: 8px 12px;
    margin: 6px auto 6px 0; /* align left */
    display: inline-block;
    max-width: 85%;
    word-break: break-word;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
/* inner bubble content: allow preserving line breaks and long words */
.msg-sent, .msg-received {
    white-space: pre-wrap; /* preserve new lines */
    overflow-wrap: break-word;
    word-break: break-word;
}

/* timestamp inside bubbles */
.msg-time {
    display: block;
    font-size: 0.75rem;
    color: rgba(255,255,255,0.85);
    opacity: 0.9;
    margin-top: 6px;
    text-align: right;
}
.msg-received .msg-time {
    color: rgba(0,0,0,0.55);
}

/* arrival animation (fade + slight slide up) */
.msg-enter {
    animation: msgIn 360ms cubic-bezier(.2,.9,.2,1);
}
@keyframes msgIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* responsiveness tweaks */
@media (max-width: 576px) {
    .msg-sent, .msg-received { max-width: 72%; }
}
.messaging-chat-footer {
    display: flex;
    gap: 8px;
}

/* Micro-tweaks to match site card conventions (used in index.php) */
.messaging-main.card { border-radius: 0 6px 6px 0; }
.messaging-main.card .card-body { padding: 1rem; }
.messaging-sidebar.card.shadow-sm, .messaging-main.card.shadow-sm { box-shadow: 0 .125rem .25rem rgba(0,0,0,.075) !important; }
.messaging-sidebar .card-header, .messaging-main .card-header { padding: 0.5rem 0.75rem; font-size: 0.95rem; }

/* Apply sidebar-like layout to the main panel but wider and anchored to the right */
.messaging-main.card {
    position: fixed;
    top: var(--bs-navbar-height, 56px);
    right: 12px;
    bottom: 12px;
    /* make it wider than the sidebar: leave space for sidebar (approx 380px) */
    left: calc(380px + 24px);
    width: auto; /* left/right control width */
    min-width: 480px;
    max-width: calc(100% - 380px - 24px);
    background: var(--bs-card-bg, #fff);
    border-left: 1px solid rgba(0,0,0,0.06);
    overflow: auto;
    z-index: 900; /* lowered so dropdowns and fixed footer sit above */
}

@media (max-width: 992px) {
    .messaging-sidebar { display: none; }
    .messaging-main.card { position: static; left: auto; right: auto; top: auto; bottom: auto; margin-left: 0; min-width: 0; }
}
