/**
 * Messaging — matches DESIGN.md + approved two-panel chat UI.
 * All rules scoped under #messagingPage to avoid layout conflicts.
 */

#messagingPage,
#projectChatContainer,
#userModal {
    --ds-navy: #122d50;
    --ds-navy-deep: #071b34;
    --ds-orange: #f15e22;
    --ds-orange-hover: #d94f18;
    --ds-orange-active-bg: rgba(241, 94, 34, 0.14);
    --ds-canvas: #f4f4f4;
    --ds-surface: #ffffff;
    --ds-surface-2: #f8f9fa;
    --ds-hairline: #e9e9e9;
    --ds-hairline-strong: #dee2e6;
    --ds-ink: #122d50;
    --ds-ink-muted: #6c757d;
    --ds-bubble-theirs-bg: var(--ds-surface);
    --ds-bubble-theirs-border: var(--ds-hairline);
    --ds-bubble-theirs-text: var(--ds-ink);
    --ds-bubble-mine-bg: var(--ds-navy);
    --ds-bubble-mine-text: #ffffff;
    --ds-mine-accent: var(--ds-navy);
    --ds-mine-accent-hover: #0c1f38;
    --ds-radius: 8px;
    --ds-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

/* DESIGN.md dark palette: surface-dark-canvas / surface-dark-1 / surface-dark-2 */
body.mod-skin-dark:not(.mod-skin-light) #messagingPage,
body.mod-skin-dark:not(.mod-skin-light) #projectChatContainer,
body.mod-skin-dark:not(.mod-skin-light) #userModal,
.mod-skin-dark:not(.mod-skin-light) #messagingPage,
.mod-skin-dark:not(.mod-skin-light) #projectChatContainer,
.mod-skin-dark:not(.mod-skin-light) #userModal {
    --ds-canvas: #15171d;
    --ds-surface: #1f2129;
    --ds-surface-2: #252830;
    --ds-hairline: rgba(255, 255, 255, 0.1);
    --ds-hairline-strong: rgba(255, 255, 255, 0.14);
    --ds-ink: #dfe7f2;
    --ds-ink-muted: #a0aec0;
    --ds-orange-active-bg: rgba(241, 94, 34, 0.22);
    --ds-bubble-theirs-bg: #252830;
    --ds-bubble-theirs-border: rgba(255, 255, 255, 0.1);
    --ds-bubble-theirs-text: #dfe7f2;
    --ds-bubble-mine-bg: var(--ds-orange);
    --ds-bubble-mine-text: #ffffff;
    --ds-mine-accent: var(--ds-orange);
    --ds-mine-accent-hover: var(--ds-orange-hover);
    --ds-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

/* ---- Shell: two columns with gutter between panels ---- */
.messaging-page-outer {
    margin-bottom: 1rem;
    background: var(--ds-canvas);
}

#messagingPage.messaging-page {
    display: grid;
    grid-template-columns: minmax(260px, 28%) 1fr;
    column-gap: 0.2rem;
    row-gap: 0.2rem;
    height: calc(100vh - 210px);
    min-height: 520px;
    max-height: 900px;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
}

#messagingPage .messaging-sidebar-col,
#messagingPage .messaging-main-col,
#projectChatContainer.messaging-main-col {
    height: 100%;
    min-height: 0;
    min-width: 0;
    border: 1px solid var(--ds-hairline);
    border-radius: var(--ds-radius);
    box-shadow: var(--ds-shadow);
    overflow: hidden;
}

#messagingPage .messaging-sidebar-col {
    background: var(--ds-surface);
}

#messagingPage .messaging-main-col,
#projectChatContainer.messaging-main-col {
    background: var(--ds-canvas);
}

#projectChatContainer .project-chat-pane {
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

#projectChatContainer .project-chat-list-pane,
#projectChatContainer .project-chat-thread-pane {
    flex: 1 1 auto;
}

#projectChatContainer #chatThread {
    min-height: 0;
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    height: 100%;
}

/* ---- Sidebar header ---- */
#messagingPage .messaging-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1rem 0.65rem;
    flex-shrink: 0;
}

#messagingPage .messaging-sidebar-title {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 900;
    color: var(--ds-ink);
    text-transform: none;
}

#messagingPage .messaging-search-wrap,
#projectChatContainer .messaging-search-wrap {
    padding: 0 1rem 0.75rem;
    flex-shrink: 0;
}

#projectChatContainer .project-chat-search-wrap {
    width: 100%;
    margin-top: 1rem;
    padding: 0 1rem 1rem;
    flex-shrink: 0;
}

#projectChatContainer .project-chat-search-wrap .project-list-filter-label {
    display: block;
    margin-bottom: 0.35rem;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--ds-ink-muted);
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

#projectChatContainer .project-chat-search-wrap .input-group {
    width: 100%;
    flex-wrap: nowrap;
}

#projectChatContainer .project-chat-search-icon {
    background-color: #f8f9fa;
    border: 1px solid #d1d5db;
    border-right: none;
    color: var(--ds-ink-muted);
    border-radius: 0;
    min-height: 40px;
}

#projectChatContainer .project-chat-search-input {
    border: 1px solid #d1d5db;
    border-left: none;
    background-color: #ffffff;
    color: var(--ds-ink);
    border-radius: 0;
    box-shadow: none;
    min-height: 40px;
}

#projectChatContainer .project-chat-search-input:focus {
    border-color: var(--ds-navy);
    box-shadow: none;
}

#projectChatContainer .project-chat-search-wrap .input-group:focus-within .project-chat-search-icon {
    background-color: var(--ds-navy);
    border-color: var(--ds-navy);
    color: #ffffff;
}

#projectChatContainer .project-chat-clear-btn {
    background: #f8f9fa;
    color: var(--ds-ink-muted);
    border: 1px solid #d1d5db !important;
    border-left: 0 !important;
    min-width: 2.5rem;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: none !important;
}

#projectChatContainer .project-chat-clear-btn:hover,
#projectChatContainer .project-chat-clear-btn:focus {
    background: #eef1f4;
    color: var(--ds-ink);
    border-color: #d1d5db !important;
    box-shadow: none !important;
}

@media (max-width: 767.98px) {
    #projectChatContainer .project-chat-search-wrap {
        max-width: none;
        padding: 0 1rem 0.85rem;
    }
}

#messagingPage .messaging-search-field,
#userModal .messaging-search-field,
#projectChatContainer .messaging-search-field {
    border-radius: var(--ds-radius) !important;
    border: 1px solid var(--ds-hairline-strong) !important;
    background: var(--ds-surface-2) !important;
    overflow: hidden;
}

#messagingPage .messaging-search-field:focus-within,
#userModal .messaging-search-field:focus-within,
#projectChatContainer .messaging-search-field:focus-within {
    border-color: var(--ds-navy) !important;
    box-shadow: 0 0 0 0.15rem rgba(18, 45, 80, 0.15) !important;
}

/* hbl-search-icon inside messaging: transparent, no border block */
#messagingPage .messaging-search-field .hbl-search-icon,
#userModal .messaging-search-field .hbl-search-icon,
#projectChatContainer .messaging-search-field .hbl-search-icon {
    background-color: transparent !important;
    border: none !important;
    border-right: none !important;
    color: var(--ds-ink-muted) !important;
}

/* suppress global focus-within icon bg change for messaging */
#messagingPage .messaging-search-field.hbl-search:focus-within .hbl-search-icon,
#userModal .messaging-search-field.hbl-search:focus-within .hbl-search-icon,
#projectChatContainer .messaging-search-field.hbl-search:focus-within .hbl-search-icon {
    background-color: transparent !important;
    border: none !important;
    color: var(--ds-navy) !important;
}

#messagingPage .messaging-search-field.hbl-search:focus-within .hbl-search-input,
#userModal .messaging-search-field.hbl-search:focus-within .hbl-search-input,
#projectChatContainer .messaging-search-field.hbl-search:focus-within .hbl-search-input {
    border-color: transparent !important;
    box-shadow: none !important;
}

#messagingPage .messaging-search-input,
#userModal .messaging-search-input,
#projectChatContainer .messaging-search-input {
    border: none !important;
    background: transparent !important;
    background-color: transparent !important;
    font-size: 0.875rem;
    color: var(--ds-ink) !important;
    box-shadow: none !important;
}

#messagingPage .messaging-search-input:focus,
#userModal .messaging-search-input:focus,
#projectChatContainer .messaging-search-input:focus {
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
    background-color: transparent !important;
    color: var(--ds-ink) !important;
}

#messagingPage .messaging-search-input::placeholder,
#userModal .messaging-search-input::placeholder,
#projectChatContainer .messaging-search-input::placeholder {
    color: var(--ds-ink-muted);
}

#messagingPage .messaging-conversation-list,
#projectChatContainer .messaging-conversation-list {
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0 0.5rem 0.5rem;
    min-height: 0;
}

/* ---- Conversation row (horizontal, like reference mockup) ---- */
#messagingPage .conversation-item,
#projectChatContainer .conversation-item {
    padding: 0.7rem 0.65rem;
    margin-bottom: 1px;
    border-radius: var(--ds-radius);
    border-left: 3px solid transparent;
    cursor: pointer;
    transition: background-color 0.12s ease;
}

#messagingPage .conversation-item:hover,
#projectChatContainer .conversation-item:hover {
    background-color: var(--ds-surface-2);
}

#messagingPage .conversation-item.is-active,
#projectChatContainer .conversation-item.is-active {
    background-color: var(--ds-orange-active-bg);
    border-left-color: var(--ds-orange);
}

#messagingPage .conversation-avatar,
#projectChatContainer .conversation-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    margin-right: 0.7rem;
}

#messagingPage .conversation-avatar--initials,
#messagingPage .conversation-avatar--project,
#projectChatContainer .conversation-avatar--initials,
#projectChatContainer .conversation-avatar--project {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.02em;
}

#messagingPage .conversation-avatar--project,
#projectChatContainer .conversation-avatar--project {
    background: rgba(43, 108, 176, 0.18);
    color: var(--ds-navy);
    font-size: 1rem;
}

#messagingPage .conversation-item-body,
#messagingPage .min-width-0,
#projectChatContainer .conversation-item-body,
#projectChatContainer .min-width-0 {
    min-width: 0;
}

#messagingPage .conversation-item-name,
#projectChatContainer .conversation-item-name {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--ds-ink);
    display: block;
}

#messagingPage .conversation-item-time,
#projectChatContainer .conversation-item-time {
    font-size: 0.68rem;
    color: var(--ds-ink-muted);
    white-space: nowrap;
}

#messagingPage .conversation-item-preview,
#projectChatContainer .conversation-item-preview {
    font-size: 0.8rem;
    color: var(--ds-ink-muted);
    margin-top: 2px;
    line-height: 1.3;
}

#messagingPage .messaging-unread-badge,
#projectChatContainer .messaging-unread-badge {
    min-width: 1.4rem;
    height: 1.4rem;
    padding: 0 0.4rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--ds-orange);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    border-radius: 9999px;
}

/* In the selected conversation, show the unread count as plain text
   instead of a circular badge, but keep the row's active highlight. */
#messagingPage .conversation-item.is-active .messaging-unread-badge,
#projectChatContainer .conversation-item.is-active .messaging-unread-badge {
    min-width: 0;
    height: auto;
    padding: 0;
    background: transparent;
    color: var(--ds-orange);
    border-radius: 0;
    display: inline;
}

/* ---- Empty / thread panel ---- */
#messagingPage .messaging-thread,
#projectChatContainer .messaging-thread {
    min-height: 0;
    height: 100%;
}

#messagingPage .messaging-empty-state,
#projectChatContainer .messaging-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--ds-ink-muted);
    padding: 2rem;
    background: var(--ds-canvas);
}

#messagingPage .messaging-empty-icon,
#projectChatContainer .messaging-empty-icon {
    font-size: 2.25rem;
    margin-bottom: 0.75rem;
    opacity: 0.35;
    color: var(--ds-ink-muted);
}

#messagingPage .chatheight,
#projectChatContainer .chatheight {
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--ds-canvas);
    position: relative;
    overflow: hidden;
}

/* ---- Chat header ---- */
#messagingPage .messaging-chat-header,
#projectChatContainer .messaging-chat-header {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    padding: 0.85rem 1.15rem;
    background: var(--ds-surface);
    border-bottom: 1px solid var(--ds-hairline);
    flex-shrink: 0;
}

#messagingPage .messaging-chat-header-top,
#projectChatContainer .messaging-chat-header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

#messagingPage .messaging-chat-header-info,
#projectChatContainer .messaging-chat-header-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

#messagingPage .messaging-chat-header-avatar,
#projectChatContainer .messaging-chat-header-avatar {
    width: 42px !important;
    height: 42px !important;
    margin-right: 0 !important;
}

#messagingPage .messaging-chat-header-name,
#projectChatContainer .messaging-chat-header-name {
    font-size: 1rem;
    font-weight: 700;
    color: var(--ds-ink);
}

#messagingPage .messaging-chat-header-meta,
#projectChatContainer .messaging-chat-header-meta {
    font-size: 0.78rem;
    color: var(--ds-ink-muted);
}

#messagingPage .messaging-chat-header-close {
    display: none;
}

#messagingPage .messaging-chat-header-search {
    display: none;
}

#messagingPage .messaging-chat-header-meta-project {
    display: none;
}

#projectChatContainer .messaging-chat-header-meta-default {
    display: none;
}

#projectChatContainer .messaging-chat-header-meta-project {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: rgba(255, 255, 255, 0.9);
}

#projectChatContainer .messaging-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #21d07a;
    box-shadow: 0 0 0 2px rgba(33, 208, 122, 0.2);
    flex-shrink: 0;
}

#projectChatContainer .messaging-chat-header {
    background: linear-gradient(135deg, #173762 0%, #122d50 55%, #0e2542 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    padding: 0.8rem 1rem;
}

#projectChatContainer .messaging-chat-header-name {
    color: #ffffff;
    font-size: 1.05rem;
    font-weight: 700;
}

#projectChatContainer .messaging-chat-header-avatar {
    width: 44px !important;
    height: 44px !important;
    border: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

#projectChatContainer .messaging-chat-header .conversation-avatar--project {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
}

#projectChatContainer .messaging-chat-header-back {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.95);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color 0.2s ease, transform 0.2s ease;
    margin-left: 0.5rem;
    font-size: 1rem;
}

#projectChatContainer .messaging-chat-header-back:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateX(-2px);
}

#projectChatContainer .messaging-chat-header-close {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: rgba(255, 255, 255, 0.86);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: default;
    pointer-events: none;
    font-size: 0.95rem;
}

/* ---- Messages ---- */
#messagingPage #messageContainer,
#messagingPage .messaging-message-container,
#projectChatContainer #messageContainer,
#projectChatContainer .messaging-message-container {
    position: relative;
    flex: 1;
    min-height: 0;
    min-height: 0;
    overflow-y: auto;
    padding: 1rem 1.15rem;
    background: var(--ds-canvas);
}

/* Load earlier — first in thread, centered pill overlapping messages */
#messagingPage .messaging-load-older,
#projectChatContainer .messaging-load-older,
.messaging-message-container .messaging-load-older {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    margin: -0.35rem 0 -1.75rem;
    padding: 0.35rem 0 1.75rem;
}

#messagingPage .messaging-load-older-btn,
#projectChatContainer .messaging-load-older-btn,
.messaging-message-container .messaging-load-older-btn {
    border: 1px solid var(--ds-hairline-strong);
    background: var(--ds-surface);
    color: var(--ds-ink-muted);
    border-radius: 9999px;
    padding: 6px 14px;
    font-size: 0.68rem;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(18, 45, 80, 0.1);
    white-space: nowrap;
}

#messagingPage .messaging-load-older-btn:hover:not(:disabled),
#projectChatContainer .messaging-load-older-btn:hover:not(:disabled) {
    border-color: var(--ds-navy);
    color: var(--ds-navy);
}

#messagingPage .messaging-load-older-btn:disabled,
#projectChatContainer .messaging-load-older-btn:disabled {
    opacity: 0.7;
    cursor: wait;
}

#messagingPage .messaging-message,
.messaging-message-container .messaging-message {
    margin-bottom: 1rem;
}

/* Avatar left, bubble + timestamp stacked in a column on the right */
#messagingPage .messaging-message-row,
.messaging-message-container .messaging-message-row {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

#messagingPage .messaging-message-row--mine,
.messaging-message-container .messaging-message-row--mine {
    justify-content: flex-end;
}

#messagingPage .messaging-message-row--theirs,
.messaging-message-container .messaging-message-row--theirs {
    justify-content: flex-start;
}

#messagingPage .messaging-message-content--mine,
#messagingPage .messaging-message-content--theirs,
.messaging-message-container .messaging-message-content--mine,
.messaging-message-container .messaging-message-content--theirs {
    max-width: min(70%, 480px);
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
}

#messagingPage .messaging-message-content--mine,
.messaging-message-container .messaging-message-content--mine {
    align-items: flex-end;
}

#messagingPage .message-avatar,
.messaging-message-container .message-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    flex-shrink: 0;
    align-self: flex-start;
    object-fit: cover;
}

#messagingPage .message-avatar--initials,
#messagingPage .message-avatar--mine,
.messaging-message-container .message-avatar--initials,
.messaging-message-container .message-avatar--mine {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 700;
    color: #fff;
    background: var(--ds-mine-accent);
}

#messagingPage .message-avatar--bot,
.messaging-message-container .message-avatar--bot {
    background: #122d50 !important;
    color: #fff;
}

#messagingPage .msg-meta,
.messaging-message-container .msg-meta {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--ds-ink-muted);
    margin: 0;
    line-height: 1.2;
}

#messagingPage .message-bubble,
.messaging-message-container .message-bubble {
    display: inline-block;
    max-width: 100%;
    padding: 0.6rem 0.85rem;
    border-radius: 12px;
    font-size: 0.875rem;
    line-height: 1.45;
    word-break: break-word;
}

#messagingPage .message-bubble--theirs,
.messaging-message-container .message-bubble--theirs {
    background: var(--ds-bubble-theirs-bg);
    color: var(--ds-bubble-theirs-text);
    border: 1px solid var(--ds-bubble-theirs-border);
}

#messagingPage .message-bubble--mine,
.messaging-message-container .message-bubble--mine {
    background: var(--ds-bubble-mine-bg);
    color: var(--ds-bubble-mine-text);
    border: none;
}

#messagingPage .message-bubble--mine a,
.messaging-message-container .message-bubble--mine a {
    color: #ffffff;
    text-decoration: underline;
    text-underline-offset: 2px;
}

#messagingPage .message-bubble--mine a:hover,
.messaging-message-container .message-bubble--mine a:hover {
    color: #eef6ff;
}

#messagingPage .message-bubble--theirs a,
.messaging-message-container .message-bubble--theirs a {
    color: var(--ds-ink);
    text-decoration: underline;
    text-underline-offset: 2px;
}

#messagingPage .message-bubble--theirs a:hover,
.messaging-message-container .message-bubble--theirs a:hover {
    color: var(--ds-orange);
}

#messagingPage .message-timestamp,
.messaging-message-container .message-timestamp {
    font-size: 0.68rem;
    color: var(--ds-ink-muted);
    margin: 0.15rem 0 0;
    padding: 0;
    line-height: 1.3;
    width: 100%;
}

#messagingPage .messaging-message-content--theirs .message-timestamp,
.messaging-message-container .messaging-message-content--theirs .message-timestamp {
    text-align: left;
}

#messagingPage .messaging-message-content--mine .message-timestamp,
.messaging-message-container .messaging-message-content--mine .message-timestamp {
    text-align: right;
}

#messagingPage .message-read-status--read {
    color: var(--ds-orange);
}

/* Image attachment — orange frame + bottom caption (reference mockup) */
#messagingPage .message-attachment-card,
.messaging-message-container .message-attachment-card {
    max-width: min(280px, 100%);
    margin-top: 0.35rem;
    background: transparent;
    border: none;
}

#messagingPage .message-attachment-card-frame,
.messaging-message-container .message-attachment-card-frame {
    border: 3px solid var(--ds-mine-accent);
    border-radius: 14px;
    overflow: hidden;
    background: #0a0a0a;
}

#messagingPage .message-attachment-card-image-btn,
.messaging-message-container .message-attachment-card-image-btn {
    display: block;
    width: 100%;
    border: 0;
    padding: 0;
    margin: 0;
    background: #111;
    cursor: zoom-in;
    line-height: 0;
}

#messagingPage .message-attachment-card-image,
.messaging-message-container .message-attachment-card-image {
    width: 100%;
    max-height: 220px;
    object-fit: cover;
    display: block;
}

#messagingPage .message-attachment-card-caption,
.messaging-message-container .message-attachment-card-caption {
    background: var(--ds-mine-accent);
    color: #fff;
    padding: 0.45rem 0.7rem;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.35;
    text-align: left;
}

#messagingPage .message-attachment-grid,
.messaging-message-container .message-attachment-grid {
    display: grid;
    gap: 2px;
    background: var(--ds-mine-accent);
}

#messagingPage .message-attachment-grid--1,
.messaging-message-container .message-attachment-grid--1 {
    grid-template-columns: 1fr;
}

#messagingPage .message-attachment-grid--2,
.messaging-message-container .message-attachment-grid--2 {
    grid-template-columns: 1fr 1fr;
}

#messagingPage .message-attachment-grid--3,
#messagingPage .message-attachment-grid--4,
.messaging-message-container .message-attachment-grid--3,
.messaging-message-container .message-attachment-grid--4 {
    grid-template-columns: 1fr 1fr;
}

#messagingPage .message-attachment-grid .message-attachment-card-image-btn,
.messaging-message-container .message-attachment-grid .message-attachment-card-image-btn {
    aspect-ratio: 1;
    height: 100%;
}

#messagingPage .message-attachment-grid .message-attachment-card-image,
.messaging-message-container .message-attachment-grid .message-attachment-card-image {
    width: 100%;
    height: 100%;
    max-height: none;
    min-height: 72px;
    object-fit: cover;
}

#messagingPage .message-attachment-download,
.messaging-message-container .message-attachment-download {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.4rem;
    color: var(--ds-mine-accent);
    font-size: 0.72rem;
    font-weight: 600;
    text-decoration: none;
}

#messagingPage .message-file-attachment,
.messaging-message-container .message-file-attachment {
    margin-top: 0.25rem;
    padding: 0.45rem 0.65rem;
    background: var(--ds-surface);
    border: 1px solid var(--ds-hairline);
    border-radius: var(--ds-radius);
    font-size: 0.82rem;
}

#messagingPage .message-file-attachment a,
.messaging-message-container .message-file-attachment a {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--ds-ink);
    font-weight: 600;
    text-decoration: none;
    word-break: break-word;
}

#messagingPage .message-file-attachment a:hover,
.messaging-message-container .message-file-attachment a:hover {
    color: var(--ds-orange);
    text-decoration: underline;
}

#messagingPage .message-bubble--mine .message-file-attachment a,
.messaging-message-container .message-bubble--mine .message-file-attachment a {
    color: var(--ds-ink);
}

#messagingPage .message-bubble--mine .message-file-attachment a:hover,
.messaging-message-container .message-bubble--mine .message-file-attachment a:hover {
    color: var(--ds-orange);
}

#messagingPage .message-bubble--theirs .message-file-attachment a,
.messaging-message-container .message-bubble--theirs .message-file-attachment a {
    color: var(--ds-ink);
}

#messagingPage .message-bubble--theirs .message-file-attachment a:hover,
.messaging-message-container .message-bubble--theirs .message-file-attachment a:hover {
    color: var(--ds-orange);
}

#messagingPage .message-attachment-download:hover,
.messaging-message-container .message-attachment-download:hover {
    color: var(--ds-mine-accent-hover);
    text-decoration: underline;
}

#messagingPage .message-attachment-download-list,
.messaging-message-container .message-attachment-download-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
    margin-top: 0.4rem;
}

/* ---- Composer ---- */
#messagingPage .messaging-composer-footer,
#projectChatContainer .messaging-composer-footer {
    flex-shrink: 0;
    background: var(--ds-surface);
    border-top: 1px solid var(--ds-hairline);
    padding: 0.65rem 1rem 0.5rem;
}

#projectChatContainer .messaging-composer-footer {
    margin-top: auto;
}

#messagingPage .compose-box,
#projectChatContainer .compose-box {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    background: var(--ds-surface-2);
    border: 1px solid var(--ds-hairline-strong);
    border-radius: 12px;
    padding: 0.35rem 0.45rem;
    min-height: 48px;
    position: relative;
}

#messagingPage .messaging-composer-tools,
#projectChatContainer .messaging-composer-tools {
    display: flex;
    flex-shrink: 0;
    align-self: center;
}

#messagingPage .messaging-composer-tool-btn,
#projectChatContainer .messaging-composer-tool-btn {
    width: 30px;
    height: 30px;
    border: none;
    background: transparent;
    color: var(--ds-ink-muted);
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

#messagingPage .messaging-composer-tool-btn:hover:not(:disabled),
#projectChatContainer .messaging-composer-tool-btn:hover:not(:disabled) {
    color: var(--ds-orange);
    background: var(--ds-orange-active-bg);
}

#messagingPage .compose-input,
#projectChatContainer .compose-input {
    flex: 1;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    resize: none;
    min-height: 34px;
    max-height: 110px;
    font-size: 0.875rem;
    color: var(--ds-ink);
    padding: 0.35rem 0.25rem;
}

#messagingPage .hblbot-suggestion,
#projectChatContainer .hblbot-suggestion {
    position: absolute;
    left: 42px;
    right: 48px;
    bottom: calc(100% + 8px);
    display: none;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--ds-hairline-strong);
    border-radius: 8px;
    background: var(--ds-surface);
    color: var(--ds-ink);
    box-shadow: 0 10px 26px rgba(18, 45, 80, 0.16);
    cursor: pointer;
    z-index: 5;
}

#messagingPage .hblbot-suggestion.is-visible,
#projectChatContainer .hblbot-suggestion.is-visible {
    display: flex;
}

#messagingPage .hblbot-suggestion:hover,
#messagingPage .hblbot-suggestion:focus,
#projectChatContainer .hblbot-suggestion:hover,
#projectChatContainer .hblbot-suggestion:focus {
    border-color: var(--ds-orange);
    outline: none;
}

.hblbot-suggestion-avatar,
.ai-thinking-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: #122d50;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
}

.hblbot-suggestion-main {
    min-width: 0;
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}

.hblbot-suggestion-main strong {
    font-size: 0.84rem;
}

.hblbot-suggestion-main small {
    color: var(--ds-ink-muted);
    font-size: 0.72rem;
}

#messagingPage .message-send-btn,
#projectChatContainer .message-send-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: var(--ds-orange);
    color: #fff;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    align-self: center;
}

#messagingPage .message-send-btn:hover:not(:disabled),
#projectChatContainer .message-send-btn:hover:not(:disabled) {
    background: var(--ds-orange-hover);
}

#messagingPage .message-send-btn:disabled,
#projectChatContainer .message-send-btn:disabled {
    background: #adb5bd;
    cursor: not-allowed;
}

#messagingPage .composer-hint,
#projectChatContainer .composer-hint {
    font-size: 0.68rem;
    color: var(--ds-ink-muted);
    text-align: center;
    margin: 0.35rem 0 0;
}

#messagingPage #attachmentPreview,
#messagingPage .messaging-attachment-preview,
#projectChatContainer #attachmentPreview,
#projectChatContainer .messaging-attachment-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0.35rem 0 0;
}

#messagingPage .messaging-typing-indicator,
#projectChatContainer .messaging-typing-indicator {
    padding: 0 1rem 0.25rem;
    font-size: 0.78rem;
    color: var(--ds-ink-muted);
}

#messagingPage #messageList,
#projectChatContainer #messageList {
    padding: 0.25rem 0;
}

#messagingPage .hide,
#projectChatContainer .hide {
    display: none !important;
}

/* Legacy bubbles (AJAX inserts) */
#messagingPage .receiver,
#projectChatContainer .receiver {
    background: var(--ds-bubble-theirs-bg);
    border: 1px solid var(--ds-bubble-theirs-border);
    color: var(--ds-bubble-theirs-text);
    padding: 0.6rem 0.85rem;
    border-radius: 12px;
}

#messagingPage .sender,
#projectChatContainer .sender {
    background: var(--ds-bubble-mine-bg);
    color: var(--ds-bubble-mine-text);
    padding: 0.6rem 0.85rem;
    border-radius: 12px;
}

#messagingPage .msg-box,
#projectChatContainer .msg-box {
    display: flex;
    align-items: flex-end;
}

/* Image preview modal */
.message-image-preview-dialog {
    width: 1100px !important;
    max-width: calc(100vw - 2rem) !important;
    height: calc(100vh - 2rem) !important;
    max-height: calc(100vh - 2rem) !important;
    margin: 1rem auto !important;
}

.message-image-preview-modal .modal-content {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.message-image-preview-modal .modal-body {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    padding: 0;
}

.message-image-preview-viewport {
    width: 100%;
    height: 100%;
    overflow: auto;
    padding: 1rem;
}

.message-image-preview-stage {
    position: relative;
    min-width: 100%;
    min-height: 100%;
}

.message-image-preview-full {
    position: absolute;
    max-width: none;
    max-height: none;
    border-radius: 8px;
}

.message-image-preview-close {
    border: 0;
    background: #e9ecef;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 1.3rem;
    cursor: pointer;
}

.message-image-thumb {
    max-width: 140px;
    border-radius: 6px;
}

.message-image-preview-trigger {
    border: 0;
    background: transparent;
    padding: 0;
    cursor: zoom-in;
}

.composer-image-box {
    position: relative;
    display: inline-block;
}

.composer-image-thumb {
    width: 90px;
    height: 90px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--ds-hairline-strong, #dee2e6);
}

.remove-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 50%;
    background: #dc3545;
    color: #fff;
    font-size: 11px;
    line-height: 20px;
    cursor: pointer;
}

/* New conversation modal */
.messaging-modal-header {
    background: var(--ds-navy, #122d50) !important;
    border-bottom: none;
}

.messaging-modal-header .close {
    opacity: 1;
}

#userModal .messaging-search-wrap {
    padding: 0;
}

#userModal .messaging-search-field {
    width: 100%;
    border: 1px solid var(--ds-hairline-strong, #dee2e6);
    background: var(--ds-surface-2, #f8f9fa);
    box-shadow: none;
}

#userModal .messaging-search-field:focus-within {
    border-color: var(--ds-navy, #122d50);
    box-shadow: 0 0 0 0.15rem rgba(18, 45, 80, 0.12);
}

#userModal .messaging-user-list {
    max-height: 380px;
    overflow-y: auto;
}

#userModal .user-row {
    gap: 0.65rem;
    padding: 0.5rem 0.65rem;
    border-radius: 6px;
    cursor: pointer;
}

#userModal .messaging-user-avatar {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    flex-shrink: 0;
    border-radius: 50%;
    object-fit: cover;
}

#userModal .messaging-user-avatar--initials {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.02em;
}

#userModal .user-row .font-weight-bold {
    font-size: 0.875rem;
    line-height: 1.25;
}

#userModal .user-row small {
    font-size: 0.75rem;
    line-height: 1.25;
}

#userModal .user-row .badge {
    font-size: 0.65rem;
    padding: 0.2rem 0.45rem;
}

#userModal .user-row:hover {
    background: var(--ds-surface-2, #f8f9fa);
}

.mod-skin-dark #userModal .user-row:hover {
    background: rgba(255, 255, 255, 0.06);
}

/* ---- Dark mode: messaging-specific tweaks (DESIGN.md) ---- */
body.mod-skin-dark:not(.mod-skin-light) #messagingPage .messaging-search-field:focus-within,
.mod-skin-dark:not(.mod-skin-light) #messagingPage .messaging-search-field:focus-within {
    border-color: var(--ds-orange);
    box-shadow: 0 0 0 0.15rem rgba(241, 94, 34, 0.28);
}

body.mod-skin-dark:not(.mod-skin-light) #messagingPage .conversation-avatar--project,
body.mod-skin-dark:not(.mod-skin-light) #projectChatContainer .conversation-avatar--project,
.mod-skin-dark:not(.mod-skin-light) #messagingPage .conversation-avatar--project,
.mod-skin-dark:not(.mod-skin-light) #projectChatContainer .conversation-avatar--project {
    background: rgba(241, 94, 34, 0.16);
    color: var(--ds-orange);
}

body.mod-skin-dark:not(.mod-skin-light) #messagingPage .messaging-load-older-btn,
body.mod-skin-dark:not(.mod-skin-light) #projectChatContainer .messaging-load-older-btn,
.mod-skin-dark:not(.mod-skin-light) #messagingPage .messaging-load-older-btn,
.mod-skin-dark:not(.mod-skin-light) #projectChatContainer .messaging-load-older-btn {
    background: var(--ds-surface-2);
    border-color: var(--ds-hairline-strong);
    color: var(--ds-ink-muted);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

body.mod-skin-dark:not(.mod-skin-light) #messagingPage .messaging-load-older-btn:hover:not(:disabled),
body.mod-skin-dark:not(.mod-skin-light) #projectChatContainer .messaging-load-older-btn:hover:not(:disabled),
.mod-skin-dark:not(.mod-skin-light) #messagingPage .messaging-load-older-btn:hover:not(:disabled),
.mod-skin-dark:not(.mod-skin-light) #projectChatContainer .messaging-load-older-btn:hover:not(:disabled) {
    border-color: var(--ds-orange);
    color: var(--ds-ink);
}

body.mod-skin-dark:not(.mod-skin-light) #messagingPage .message-send-btn:disabled,
.mod-skin-dark:not(.mod-skin-light) #messagingPage .message-send-btn:disabled {
    background: #4a5568;
    color: rgba(255, 255, 255, 0.65);
}

body.mod-skin-dark:not(.mod-skin-light) #messagingPage .message-file-attachment,
.mod-skin-dark:not(.mod-skin-light) #messagingPage .message-file-attachment {
    background: var(--ds-surface-2);
    color: var(--ds-ink);
}

body.mod-skin-dark:not(.mod-skin-light) #userModal .messaging-search-field,
.mod-skin-dark:not(.mod-skin-light) #userModal .messaging-search-field {
    background: var(--ds-surface-2, #252830);
    border: 1px solid var(--ds-hairline-strong, rgba(255, 255, 255, 0.14));
}

body.mod-skin-dark:not(.mod-skin-light) #userModal .messaging-search-field:focus-within,
.mod-skin-dark:not(.mod-skin-light) #userModal .messaging-search-field:focus-within {
    border-color: var(--ds-orange, #f15e22);
    box-shadow: 0 0 0 0.15rem rgba(241, 94, 34, 0.28);
}

body.mod-skin-dark:not(.mod-skin-light) #userModal .messaging-search-input,
.mod-skin-dark:not(.mod-skin-light) #userModal .messaging-search-input {
    color: var(--ds-ink, #dfe7f2);
}

body.mod-skin-dark:not(.mod-skin-light) #userModal .messaging-modal-header,
.mod-skin-dark:not(.mod-skin-light) #userModal .messaging-modal-header {
    background: transparent !important;
    border-bottom: 1px solid var(--ds-hairline, rgba(255, 255, 255, 0.1));
}

body.mod-skin-dark:not(.mod-skin-light) #userModal .messaging-modal-header .text-white,
.mod-skin-dark:not(.mod-skin-light) #userModal .messaging-modal-header .text-white {
    color: var(--ds-ink-muted, #a0aec0) !important;
}

body.mod-skin-dark:not(.mod-skin-light) .message-image-preview-close,
.mod-skin-dark:not(.mod-skin-light) .message-image-preview-close {
    background: #252830;
    color: #dfe7f2;
}

body.mod-skin-dark:not(.mod-skin-light) .composer-image-thumb,
.mod-skin-dark:not(.mod-skin-light) .composer-image-thumb {
    border-color: rgba(255, 255, 255, 0.14);
}

/* Project tab chat — thread panel inherits projectChatContainer tokens */
body.mod-skin-dark:not(.mod-skin-light) #projectChatContainer .chatheight,
body.mod-skin-dark:not(.mod-skin-light) #projectChatContainer .messaging-chat-header,
body.mod-skin-dark:not(.mod-skin-light) #projectChatContainer .messaging-message-container,
body.mod-skin-dark:not(.mod-skin-light) #projectChatContainer .messaging-composer-footer,
.mod-skin-dark:not(.mod-skin-light) #projectChatContainer .chatheight,
.mod-skin-dark:not(.mod-skin-light) #projectChatContainer .messaging-chat-header,
.mod-skin-dark:not(.mod-skin-light) #projectChatContainer .messaging-message-container,
.mod-skin-dark:not(.mod-skin-light) #projectChatContainer .messaging-composer-footer {
    background: var(--ds-canvas);
    color: var(--ds-ink);
}

body.mod-skin-dark:not(.mod-skin-light) #projectChatContainer .messaging-chat-header,
body.mod-skin-dark:not(.mod-skin-light) #projectChatContainer .messaging-composer-footer,
.mod-skin-dark:not(.mod-skin-light) #projectChatContainer .messaging-chat-header,
.mod-skin-dark:not(.mod-skin-light) #projectChatContainer .messaging-composer-footer {
    background: var(--ds-surface);
    border-color: var(--ds-hairline);
}

body.mod-skin-dark:not(.mod-skin-light) #projectChatContainer .compose-box,
.mod-skin-dark:not(.mod-skin-light) #projectChatContainer .compose-box {
    background: var(--ds-surface-2);
    border-color: var(--ds-hairline-strong);
}

/* Mobile: stack columns with vertical gutter */
@media (max-width: 767.98px) {
    #messagingPage.messaging-page {
        grid-template-columns: 1fr;
        column-gap: 0;
        row-gap: 1rem;
        height: auto;
        min-height: 0;
        max-height: none;
    }

    #messagingPage .messaging-sidebar-col {
        height: auto;
        max-height: 45vh;
    }

    #messagingPage .messaging-main-col {
        height: 55vh;
        min-height: 320px;
    }
}

@media (max-width: 575.98px) {

    #messagingPage .messaging-message-content--mine,
    #messagingPage .messaging-message-content--theirs {
        max-width: 85%;
    }
}

/* Sidebar Filter Tabs styling to match screenshot */
.messaging-filters-wrap {
    padding: 0 1rem 0.65rem;
    gap: 0.5rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    flex-shrink: 0;
    scrollbar-width: none;
    /* Hide scrollbar for Chrome/Safari/Firefox */
}

.messaging-filters-wrap::-webkit-scrollbar {
    display: none;
}

.messaging-filter-btn {
    border: none;
    background: transparent;
    padding: 6px 14px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--ds-ink-muted, #6c757d);
    border-radius: 9999px;
    cursor: pointer;
    transition: all 0.15s ease-in-out;
    outline: none !important;
    white-space: nowrap;
}

.messaging-filter-btn:hover {
    color: var(--ds-navy, #122d50);
    background-color: rgba(18, 45, 80, 0.04);
}

.messaging-filter-btn.active {
    color: #1a73e8;
    /* Blue text */
    background-color: rgba(26, 115, 232, 0.08);
    /* Very light blue background */
}

/* Dark mode overrides for filter tabs */
body.mod-skin-dark:not(.mod-skin-light) .messaging-filter-btn:hover,
.mod-skin-dark:not(.mod-skin-light) .messaging-filter-btn:hover {
    color: var(--ds-orange, #f15e22);
    background-color: rgba(241, 94, 34, 0.08);
}

body.mod-skin-dark:not(.mod-skin-light) .messaging-filter-btn.active,
.mod-skin-dark:not(.mod-skin-light) .messaging-filter-btn.active {
    color: var(--ds-orange, #f15e22);
    background-color: rgba(241, 94, 34, 0.15);
}

.conversation-item.is-filtered-out {
    display: none !important;
}

/* Inside message bubble metadata (time & tick status) */
.message-bubble {
    display: inline-flex;
    flex-direction: column;
    width: fit-content;
    min-width: 0;
    align-items: flex-start;
}
.message-text {
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
}
.ai-markdown-message {
    white-space: normal;
}
.ai-markdown-message > :first-child {
    margin-top: 0;
}
.ai-markdown-message > :last-child {
    margin-bottom: 0;
}
.ai-markdown-message ul,
.ai-markdown-message ol {
    padding-left: 1.25rem;
}
.ai-markdown-message table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
}
.ai-markdown-message th,
.ai-markdown-message td {
    border: 1px solid rgba(18, 45, 80, 0.18);
    padding: 0.35rem 0.5rem;
}
.message-text--collapsed {
    max-height: 96px;
    overflow: hidden;
    position: relative;
}
.message-show-more-btn {
    border: 0;
    background: transparent;
    color: inherit;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 0 0;
    cursor: pointer;
    opacity: 0.85;
}
.message-show-more-btn:hover {
    text-decoration: underline;
    opacity: 1;
}
.message-meta-inside {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    font-size: 0.65rem;
    margin-top: 4px;
    gap: 4px;
    opacity: 0.8;
    white-space: nowrap;
    user-select: none;
    align-self: flex-end;
}
.message-bubble--mine .message-meta-inside {
    color: rgba(255, 255, 255, 0.7);
}
.message-bubble--theirs .message-meta-inside {
    color: var(--ds-ink-muted, #6c757d);
    align-self: flex-start;
    justify-content: flex-start;
}
.message-read-status {
    display: inline-flex;
    align-items: center;
}
.message-read-status--read {
    color: #4fc3f7 !important; /* light blue/cyan for read ticks */
}

/* Dark mode: ticks on orange (mine) bubbles — make fully white & crisp */
body.mod-skin-dark:not(.mod-skin-light) .message-bubble--mine .message-meta-inside,
.mod-skin-dark:not(.mod-skin-light) .message-bubble--mine .message-meta-inside {
    color: rgba(255, 255, 255, 0.95);
    opacity: 1;
}
body.mod-skin-dark:not(.mod-skin-light) .message-bubble--mine .message-read-status,
.mod-skin-dark:not(.mod-skin-light) .message-bubble--mine .message-read-status {
    color: rgba(255, 255, 255, 0.95);
}
body.mod-skin-dark:not(.mod-skin-light) .message-bubble--mine .message-read-status--read,
.mod-skin-dark:not(.mod-skin-light) .message-bubble--mine .message-read-status--read {
    color: #122d50 !important; /* dark navy provides strong contrast against the bright orange bubble */
}
/* Dark mode: ticks on theirs bubbles — slightly brighter */
body.mod-skin-dark:not(.mod-skin-light) .message-bubble--theirs .message-meta-inside,
.mod-skin-dark:not(.mod-skin-light) .message-bubble--theirs .message-meta-inside {
    color: rgba(160, 174, 192, 0.9);
}

/* Adjust bubble width when it contains an image card to prevent empty stretching */
.message-bubble:has(.message-attachment-card) {
    width: 280px;
    max-width: 100%;
    padding: 0.5rem;
}

.ai-thinking-message {
    pointer-events: none;
}

.ai-thinking-bubble {
    flex-direction: row;
    align-items: center;
    gap: 0.35rem;
    min-height: 34px;
}

.ai-thinking-label {
    font-size: 0.85rem;
    color: var(--ds-ink-muted);
}

.ai-thinking-dots {
    display: inline-flex;
    gap: 0.18rem;
    align-items: center;
}

.ai-thinking-dots span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--ds-orange);
    opacity: 0.35;
    animation: hblbot-thinking 1.1s infinite ease-in-out;
}

.ai-thinking-dots span:nth-child(2) {
    animation-delay: 0.16s;
}

.ai-thinking-dots span:nth-child(3) {
    animation-delay: 0.32s;
}

@keyframes hblbot-thinking {
    0%, 80%, 100% {
        opacity: 0.35;
        transform: translateY(0);
    }
    40% {
        opacity: 1;
        transform: translateY(-3px);
    }
}

/* Real-time Presence Indicators */
.avatar-wrap {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 42px;
    margin-right: 0.7rem;
    flex-shrink: 0;
}
.avatar-wrap .conversation-avatar {
    margin-right: 0 !important;
}
.status-indicator {
    position: absolute;
    bottom: 0px;
    right: 0px;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    border: 2px solid var(--ds-surface, #ffffff);
    background-color: #a0aec0; /* default offline/gray */
    transition: background-color 0.3s ease, border-color 0.3s ease;
    z-index: 2;
}
.status-indicator.online {
    background-color: #28c76f; /* premium green online */
}
.presence-status-label {
    font-size: 0.75rem;
    color: var(--ds-ink-muted, #6c757d);
    font-weight: normal;
    margin-top: 2px;
}
.presence-status-label.online {
    color: #28c76f !important; /* Premium green color for Online status */
    font-weight: 500;
}

/* WhatsApp-style Sticky Date Dividers */
.messaging-date-divider {
    position: sticky;
    top: 10px;
    z-index: 10;
    text-align: center;
    margin: 1rem 0;
    pointer-events: none;
}
.messaging-date-divider-badge {
    display: inline-block;
    background-color: var(--ds-surface-variant, #f0f2f5);
    color: var(--ds-ink-muted, #54656f);
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.35rem 0.8rem;
    border-radius: 7.5px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.04);
    user-select: none;
    pointer-events: auto;
}

/* Dark mode: date divider badge — dark surface, light text */
body.mod-skin-dark:not(.mod-skin-light) .messaging-date-divider-badge,
.mod-skin-dark:not(.mod-skin-light) .messaging-date-divider-badge {
    background-color: #2a2d38;
    color: #a0aec0;
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

/* ================================================================
   GROUP MEMBERS PANEL — Right-side slide-in
   ================================================================ */

/* Outer wrapper that holds chat column + panel side-by-side */
.group-thread-wrapper {
    position: relative;
    display: flex;
    flex-direction: row;
    overflow: hidden;
    height: 100%;
    min-height: 0;
}

/* Members trigger button (the "15 members" text under group title) */
.members-trigger-btn {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    text-align: left;
    line-height: inherit;
    font-size: inherit;
    font-weight: inherit;
    transition: color 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--ds-ink-muted, #6c757d);
}

.members-trigger-btn:hover {
    color: var(--ds-navy, #122d50);
    text-decoration: underline;
}

/* Header Members button (top-right) */
.messaging-chat-header-members-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border: 1px solid var(--ds-hairline-strong, #dee2e6);
    border-radius: 9999px;
    background: transparent;
    color: var(--ds-ink-muted, #6c757d);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

.messaging-chat-header-members-btn:hover,
.messaging-chat-header-members-btn.is-active {
    background: var(--ds-navy, #122d50);
    border-color: var(--ds-navy, #122d50);
    color: #ffffff;
}

#projectChatContainer .messaging-chat-header-members-btn {
    border-color: rgba(255, 255, 255, 0.25);
    color: rgba(255, 255, 255, 0.85);
}

#projectChatContainer .messaging-chat-header-members-btn:hover,
#projectChatContainer .messaging-chat-header-members-btn.is-active {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.5);
    color: #ffffff;
}

/* Panel container — slides in from the right */
.group-members-panel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 300px;
    max-width: 100%;
    background: var(--ds-surface, #ffffff);
    border-left: 1px solid var(--ds-hairline, #e9e9e9);
    border-radius: 0 var(--ds-radius, 8px) var(--ds-radius, 8px) 0;
    box-shadow: -6px 0 24px rgba(15, 23, 42, 0.09);
    transform: translateX(100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 20;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.group-members-panel.is-open {
    transform: translateX(0);
}

.group-members-panel-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* Loading spinner placeholder */
.group-members-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: var(--ds-ink-muted, #6c757d);
    font-size: 1.5rem;
    padding: 2rem;
}

/* Panel inner wrapper */
.group-members-panel-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* Panel header */
.group-members-panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 1.1rem 1rem 0.65rem;
    flex-shrink: 0;
    border-bottom: 1px solid var(--ds-hairline, #e9e9e9);
}

.group-members-title {
    margin: 0 0 2px;
    font-size: 1rem;
    font-weight: 800;
    color: var(--ds-ink, #122d50);
}

.group-members-subtitle {
    font-size: 0.75rem;
    color: var(--ds-ink-muted, #6c757d);
    font-weight: 500;
}

.group-members-close-btn {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 50%;
    background: var(--ds-surface-2, #f8f9fa);
    color: var(--ds-ink-muted, #6c757d);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.9rem;
    flex-shrink: 0;
    transition: background 0.15s ease, color 0.15s ease;
}

.group-members-close-btn:hover {
    background: var(--ds-hairline-strong, #dee2e6);
    color: var(--ds-ink, #122d50);
}

/* Search */
.group-members-search-wrap {
    padding: 0.75rem 1rem 0.5rem;
    flex-shrink: 0;
}

.group-members-search-field {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    height: 36px;
    padding: 0 0.75rem;
    border-radius: 9999px;
    border: 1px solid var(--ds-hairline-strong, #dee2e6);
    background: var(--ds-surface-2, #f8f9fa);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.group-members-search-field:focus-within {
    border-color: var(--ds-navy, #122d50);
    box-shadow: 0 0 0 0.15rem rgba(18, 45, 80, 0.12);
}

.group-members-search-icon {
    color: var(--ds-ink-muted, #6c757d);
    font-size: 0.85rem;
    flex-shrink: 0;
    pointer-events: none;
}

.group-members-search-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 0.84rem;
    color: var(--ds-ink, #122d50);
    outline: none;
    min-width: 0;
}

.group-members-search-input::placeholder {
    color: var(--ds-ink-muted, #6c757d);
}

/* Members list */
.group-members-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.35rem 0.5rem 1rem;
}

.group-members-list::-webkit-scrollbar {
    width: 4px;
}

.group-members-list::-webkit-scrollbar-track {
    background: transparent;
}

.group-members-list::-webkit-scrollbar-thumb {
    background: var(--ds-hairline-strong, #dee2e6);
    border-radius: 4px;
}

/* Individual member row */
.group-member-row {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 0.6rem;
    border-radius: 8px;
    transition: background 0.12s ease;
}

.group-member-row:hover {
    background: var(--ds-surface-2, #f8f9fa);
}

/* Avatar */
.group-member-avatar-wrap {
    position: relative;
    flex-shrink: 0;
    width: 38px;
    height: 38px;
}

.group-member-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
}

.group-member-avatar--initials {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.02em;
    border-radius: 50%;
}

/* Online status dot */
.group-member-status-dot {
    position: absolute;
    bottom: 0px;
    right: 0px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid var(--ds-surface, #ffffff);
    background: #a0aec0;
    transition: background-color 0.3s ease;
}

.group-member-status-dot.online {
    background: #28c76f;
}

/* Member name + presence */
.group-member-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.group-member-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--ds-ink, #122d50);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.25;
}

.group-member-presence {
    font-size: 0.72rem;
    color: var(--ds-ink-muted, #6c757d);
    line-height: 1.2;
    margin-top: 1px;
}

.group-member-presence.online {
    color: #28c76f;
    font-weight: 500;
}

/* Empty state */
.group-members-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    gap: 0.5rem;
    color: var(--ds-ink-muted, #6c757d);
    font-size: 0.85rem;
}

.group-members-empty i {
    font-size: 1.75rem;
    opacity: 0.4;
}

/* Role badges */
.role-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 3px 10px;
    border-radius: 9999px;
    font-size: 0.68rem;
    font-weight: 700;
    white-space: nowrap;
    flex-shrink: 0;
    border: 1px solid transparent;
}

.role-badge--admin {
    background: rgba(155, 89, 182, 0.1);
    color: #8e44ad;
    border-color: rgba(155, 89, 182, 0.25);
}

.role-badge--sales {
    background: rgba(241, 94, 34, 0.1);
    color: #d94f18;
    border-color: rgba(241, 94, 34, 0.25);
}

.role-badge--crew {
    background: rgba(39, 174, 96, 0.1);
    color: #1e8449;
    border-color: rgba(39, 174, 96, 0.25);
}

.role-badge--customer {
    background: rgba(52, 152, 219, 0.1);
    color: #2471a3;
    border-color: rgba(52, 152, 219, 0.25);
}

.role-badge--default {
    background: rgba(108, 117, 125, 0.1);
    color: #495057;
    border-color: rgba(108, 117, 125, 0.2);
}

/* Hidden rows when search filters */
.group-member-row.is-hidden {
    display: none;
}

/* ---- Dark mode tweaks ---- */
body.mod-skin-dark:not(.mod-skin-light) .group-members-panel,
.mod-skin-dark:not(.mod-skin-light) .group-members-panel {
    background: var(--ds-surface, #1f2129);
    border-left-color: var(--ds-hairline, rgba(255,255,255,0.1));
    box-shadow: -6px 0 24px rgba(0,0,0,0.35);
}

body.mod-skin-dark:not(.mod-skin-light) .group-members-panel-header,
.mod-skin-dark:not(.mod-skin-light) .group-members-panel-header {
    border-bottom-color: var(--ds-hairline, rgba(255,255,255,0.1));
}

body.mod-skin-dark:not(.mod-skin-light) .group-members-title,
.mod-skin-dark:not(.mod-skin-light) .group-members-title {
    color: var(--ds-ink, #dfe7f2);
}

body.mod-skin-dark:not(.mod-skin-light) .group-members-close-btn,
.mod-skin-dark:not(.mod-skin-light) .group-members-close-btn {
    background: rgba(255,255,255,0.07);
    color: var(--ds-ink-muted, #a0aec0);
}

body.mod-skin-dark:not(.mod-skin-light) .group-members-close-btn:hover,
.mod-skin-dark:not(.mod-skin-light) .group-members-close-btn:hover {
    background: rgba(255,255,255,0.13);
    color: var(--ds-ink, #dfe7f2);
}

body.mod-skin-dark:not(.mod-skin-light) .group-members-search-field,
.mod-skin-dark:not(.mod-skin-light) .group-members-search-field {
    background: var(--ds-surface-2, #252830);
    border-color: var(--ds-hairline-strong, rgba(255,255,255,0.14));
}

body.mod-skin-dark:not(.mod-skin-light) .group-members-search-field:focus-within,
.mod-skin-dark:not(.mod-skin-light) .group-members-search-field:focus-within {
    border-color: var(--ds-orange, #f15e22);
    box-shadow: 0 0 0 0.15rem rgba(241,94,34,0.28);
}

body.mod-skin-dark:not(.mod-skin-light) .group-members-search-input,
.mod-skin-dark:not(.mod-skin-light) .group-members-search-input {
    color: var(--ds-ink, #dfe7f2);
}

body.mod-skin-dark:not(.mod-skin-light) .group-member-row:hover,
.mod-skin-dark:not(.mod-skin-light) .group-member-row:hover {
    background: rgba(255,255,255,0.05);
}

body.mod-skin-dark:not(.mod-skin-light) .group-member-name,
.mod-skin-dark:not(.mod-skin-light) .group-member-name {
    color: var(--ds-ink, #dfe7f2);
}

body.mod-skin-dark:not(.mod-skin-light) .group-member-status-dot,
.mod-skin-dark:not(.mod-skin-light) .group-member-status-dot {
    border-color: var(--ds-surface, #1f2129);
}

body.mod-skin-dark:not(.mod-skin-light) .messaging-chat-header-members-btn,
.mod-skin-dark:not(.mod-skin-light) .messaging-chat-header-members-btn {
    border-color: var(--ds-hairline-strong, rgba(255,255,255,0.14));
    color: var(--ds-ink-muted, #a0aec0);
}

body.mod-skin-dark:not(.mod-skin-light) .messaging-chat-header-members-btn:hover,
body.mod-skin-dark:not(.mod-skin-light) .messaging-chat-header-members-btn.is-active,
.mod-skin-dark:not(.mod-skin-light) .messaging-chat-header-members-btn:hover,
.mod-skin-dark:not(.mod-skin-light) .messaging-chat-header-members-btn.is-active {
    background: var(--ds-orange, #f15e22);
    border-color: var(--ds-orange, #f15e22);
    color: #ffffff;
}
