/* =============================================================================
   Chat module - WhatsApp-style two-pane layout, reproduced in the app's stack
   (Bootstrap + bi-* icons). Colours use rgba overlays + --bs-primary so the
   panel adapts to both the light and dark Mazer themes.
============================================================================= */

.chat-app {
    display: flex !important;
    /* The element also carries Bootstrap's .card class, which forces
       flex-direction: column - override it so the panes sit side by side. */
    flex-direction: row !important;
    /* Fallback until chatFitHeight() sets the exact px height (JS clamps to >= 320). */
    height: calc(100vh - 150px);
    min-height: 320px;
    overflow: hidden;
    padding: 0;
    margin-bottom: 0;
}

.min-w-0 {
    min-width: 0;
}

/* Custom thin scrollbars inside the chat panes */
.chat-conv-list::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-conv-list::-webkit-scrollbar-thumb,
.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, .18);
    border-radius: 4px;
}

body.theme-dark .chat-conv-list::-webkit-scrollbar-thumb,
body.theme-dark .chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, .18);
}

/* ---- Sidebar ---- */
.chat-sidebar {
    width: 340px;
    min-width: 280px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(0, 0, 0, .08);
}

.chat-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px 10px;
}

.chat-header-actions .btn {
    padding: 4px 9px;
}

.chat-search {
    position: relative;
    padding: 0 14px 12px;
}

.chat-search i {
    position: absolute;
    left: 26px;
    top: 9px;
    opacity: .5;
    font-size: 14px;
}

.chat-search input {
    width: 100%;
    border: 1px solid rgba(0, 0, 0, .1);
    border-radius: 8px;
    padding: 8px 12px 8px 34px;
    background: rgba(0, 0, 0, .03);
    outline: none;
    font-size: 14px;
}

.chat-conv-list {
    flex: 1;
    overflow-y: auto;
}

.chat-conv-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    cursor: pointer;
    border-left: 3px solid transparent;
}

.chat-conv-item:hover {
    background: rgba(0, 0, 0, .035);
}

.chat-conv-item.active {
    background: rgba(0, 0, 0, .055);
    border-left-color: var(--bs-primary);
}

.chat-avatar {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bs-primary);
    color: #fff;
    font-weight: 600;
    font-size: 15px;
    text-transform: uppercase;
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.chat-avatar.group {
    background: #6c757d;
}

.chat-avatar.sm {
    width: 38px;
    height: 38px;
    font-size: 13px;
}

.chat-conv-body {
    flex: 1;
    min-width: 0;
}

.chat-conv-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}

.chat-conv-title {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-conv-time {
    font-size: 11px;
    opacity: .6;
    flex-shrink: 0;
}

.chat-conv-preview {
    font-size: 13px;
    opacity: .7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.chat-unread {
    background: var(--bs-primary);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    padding: 0 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ---- Main pane ---- */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-main-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 20px;
    border-bottom: 1px solid rgba(0, 0, 0, .08);
}

.chat-main-title {
    font-weight: 600;
    font-size: 16px;
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-main-sub {
    font-size: 12px;
    opacity: .6;
}

.chat-close-btn {
    margin-left: auto;
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: inherit;
    opacity: .6;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-close-btn:hover {
    opacity: 1;
    background: rgba(0, 0, 0, .06);
}

body.theme-dark .chat-close-btn:hover {
    background: rgba(255, 255, 255, .08);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px 8%;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: rgba(0, 0, 0, .02);
}

/* In-chat search bar (under the header) */
.chat-search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-bottom: 1px solid rgba(0, 0, 0, .08);
    position: relative;
}

.chat-search-bar > i {
    opacity: .5;
    font-size: 14px;
}

.chat-search-bar input {
    flex: 1;
    border: 1px solid rgba(0, 0, 0, .1);
    border-radius: 8px;
    padding: 6px 12px;
    background: rgba(0, 0, 0, .03);
    outline: none;
    font-size: 14px;
}

body.theme-dark .chat-search-bar input {
    background: rgba(255, 255, 255, .05);
    border-color: rgba(255, 255, 255, .1);
    color: #e9ecef;
}

/* Typing indicator */
.chat-typing {
    padding: 2px 20px 6px;
    font-size: 12px;
    font-style: italic;
    opacity: .7;
}

/* Deleted (unsent) message placeholder */
.chat-deleted {
    font-style: italic;
    opacity: .7;
    display: flex;
    align-items: center;
    gap: 5px;
}

.chat-date-divider {
    align-self: center;
    margin: 10px 0;
}

.chat-date-divider span,
.chat-system span {
    background: rgba(0, 0, 0, .06);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: 3px 12px;
    border-radius: 10px;
    opacity: .85;
}

.chat-system {
    align-self: center;
    margin: 6px 0;
}

.chat-system span {
    text-transform: none;
    letter-spacing: normal;
    font-size: 12px;
}

.chat-bubble {
    max-width: 72%;
    width: fit-content;      /* hug the text instead of stretching */
    padding: 5px 10px 4px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.35;
    /* flex-wrap row: time tucks beside short text, drops under long text */
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    column-gap: 8px;
    position: relative;
}

.chat-msg-del {
    position: absolute;
    top: 50%;
    left: -30px;
    transform: translateY(-50%);
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #6c757d;
    opacity: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    transition: opacity .12s;
}

.chat-bubble:hover .chat-msg-del {
    opacity: .75;
}

.chat-msg-del:hover {
    opacity: 1 !important;
    background: rgba(0, 0, 0, .08);
    color: #dc3545;
}

.chat-text {
    line-height: 1.35;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.chat-bubble.in {
    align-self: flex-start;
    background: #fff;
    color: #000;             /* white bubble -> black text */
    border: 1px solid rgba(0, 0, 0, .07);
    border-top-left-radius: 4px;
}

.chat-bubble.out {
    align-self: flex-end;
    background: var(--bs-primary);
    color: #fff;
    border-top-right-radius: 4px;
}

.chat-bubble .sender {
    flex: 0 0 100%;          /* group sender name gets its own line on top */
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 2px;
    color: var(--bs-primary);
}

.chat-bubble.out .sender {
    color: rgba(255, 255, 255, .85);
}

.chat-meta {
    margin-left: auto;       /* keep time/ticks at the far right of the bubble */
    flex-shrink: 0;
    font-size: 10px;
    opacity: .7;
    display: flex;
    gap: 4px;
    align-items: center;
    line-height: 1;
    position: relative;
    top: 2px;                /* sit on the text baseline, no gap above */
}

.chat-meta i {
    font-size: 15px;         /* bigger read tick */
    line-height: 1;
}

.chat-bubble.in .chat-meta {
    color: rgba(0, 0, 0, .55);
}

/* ---- Input ---- */
.chat-input {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 12px 16px;
    border-top: 1px solid rgba(0, 0, 0, .08);
}

.chat-input textarea {
    flex: 1;
    border: 1px solid rgba(0, 0, 0, .1);
    border-radius: 18px;
    padding: 10px 16px;
    background: rgba(0, 0, 0, .03);
    outline: none;
    font-size: 14px;
    line-height: 1.4;
    resize: none;
    overflow-y: auto;
    max-height: 140px;
    min-height: 42px;
    font-family: inherit;
}

.chat-send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    flex-shrink: 0;
    background: var(--bs-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.chat-send-btn:disabled {
    opacity: .5;
}

.chat-attach-btn {
    flex-shrink: 0;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    color: #6c757d;
    margin-bottom: 0;
}

.chat-attach-btn:hover {
    background: rgba(0, 0, 0, .06);
}

.chat-attach-btn input {
    display: none;
}

body.theme-dark .chat-attach-btn:hover {
    background: rgba(255, 255, 255, .08);
}

/* ---- Image / file attachments in bubbles ---- */
.chat-bubble.img {
    padding: 4px;
}

.chat-image-link {
    flex: 0 0 100%;
    display: block;
}

.chat-image {
    display: block;
    max-width: 260px;
    width: 100%;
    border-radius: 8px;
    cursor: zoom-in;
}

/* Clickable links inside message bubbles */
.chat-bubble.out .chat-text .chat-link {
    color: #fff;
    text-decoration: underline;
}

.chat-bubble.in .chat-text .chat-link {
    color: #1f6feb;
    text-decoration: underline;
}

.chat-text .chat-link {
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* ---- Message reactions ---- */
.chat-reactions {
    flex: 0 0 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 5px;
}

.chat-reaction {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    border: 1px solid rgba(0, 0, 0, .12);
    background: rgba(255, 255, 255, .9);
    border-radius: 12px;
    padding: 1px 8px;
    font-size: 12px;
    line-height: 1.5;
    cursor: pointer;
    color: #222;
}

.chat-reaction .cnt {
    font-weight: 600;
}

.chat-reaction.mine {
    border-color: #1f6feb;
    background: rgba(31, 111, 235, .12);
    color: #1f6feb;
}

.chat-bubble.out .chat-reaction {
    background: rgba(255, 255, 255, .18);
    border-color: rgba(255, 255, 255, .35);
    color: #fff;
}

.chat-bubble.out .chat-reaction.mine {
    background: rgba(255, 255, 255, .34);
    border-color: #fff;
    color: #fff;
}

.chat-msg-react {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #6c757d;
    opacity: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.chat-bubble.in .chat-msg-react {
    right: -30px;
}

.chat-bubble.out .chat-msg-react {
    left: -58px;
}

.chat-bubble:hover .chat-msg-react {
    opacity: .75;
}

.chat-msg-react:hover {
    opacity: 1 !important;
    background: rgba(0, 0, 0, .08);
    color: #1f6feb;
}

.chat-react-pop {
    position: absolute;
    bottom: calc(100% + 4px);
    display: flex;
    gap: 2px;
    padding: 4px 6px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 22px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .16);
    z-index: 15;
}

.chat-bubble.in .chat-react-pop {
    left: 0;
}

.chat-bubble.out .chat-react-pop {
    right: 0;
}

.chat-react-cell {
    border: none;
    background: transparent;
    font-size: 20px;
    line-height: 1;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    cursor: pointer;
    transition: transform .08s ease;
}

.chat-react-cell:hover {
    background: #f1f3f5;
    transform: scale(1.15);
}

/* @mention highlight inside message bubbles */
.chat-mention {
    font-weight: 600;
    padding: 0 2px;
    border-radius: 3px;
}

.chat-bubble.in .chat-mention {
    color: #1f6feb;
    background: rgba(31, 111, 235, .10);
}

.chat-bubble.out .chat-mention {
    color: #fff;
    background: rgba(255, 255, 255, .22);
}

/* Composer wrapper anchors the emoji / mention popups above the input */
.chat-input-wrap {
    position: relative;
}

.chat-emoji-btn {
    border: none;
    background: transparent;
    color: #6b7280;
    font-size: 20px;
    line-height: 1;
    padding: 0 6px;
    cursor: pointer;
}

.chat-emoji-btn:hover,
.chat-emoji-btn.active {
    color: #1f6feb;
}

.chat-emoji-pop {
    position: absolute;
    bottom: calc(100% + 6px);
    right: 12px;
    width: 300px;
    max-height: 220px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .14);
    padding: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    z-index: 20;
}

.chat-emoji-cell {
    border: none;
    background: transparent;
    font-size: 20px;
    line-height: 1;
    width: 34px;
    height: 34px;
    border-radius: 7px;
    cursor: pointer;
}

.chat-emoji-cell:hover {
    background: #f1f3f5;
}

.chat-mention-pop {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 12px;
    min-width: 220px;
    max-width: 320px;
    max-height: 240px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .14);
    padding: 6px;
    z-index: 20;
}

.chat-mention-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-radius: 8px;
    cursor: pointer;
}

.chat-mention-item:hover {
    background: #f1f3f5;
}

.chat-mention-name {
    font-size: 13.5px;
    font-weight: 500;
    color: #111827;
}

/* Image preview lightbox */
.chat-img-modal {
    background: #111;
    border: none;
    border-radius: 10px;
    overflow: hidden;
}

.chat-img-modal-bar {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 8px;
}

.chat-img-modal-img {
    display: block;
    max-width: 100%;
    max-height: 78vh;
    margin: 0 auto 12px;
    object-fit: contain;
}

.chat-file {
    flex: 0 0 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 200px;
    padding: 4px 2px;
    text-decoration: none;
    color: inherit;
}

.chat-file-icon {
    font-size: 22px;
    flex-shrink: 0;
}

.chat-file-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-file-name {
    font-weight: 600;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-file-size {
    font-size: 11px;
    opacity: .7;
}

.chat-bubble.out .chat-file {
    color: #fff;
}

/* ---- Empty states / contact picker ---- */
.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    opacity: .6;
    padding: 24px;
}

.chat-empty i {
    font-size: 56px;
    margin-bottom: 14px;
    opacity: .5;
}

.chat-contact-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 8px;
    cursor: pointer;
    border-radius: 8px;
}

.chat-contact-item:hover {
    background: rgba(0, 0, 0, .04);
}

.chat-contact-name {
    font-weight: 600;
    font-size: 14px;
}

.chat-contact-role {
    font-size: 12px;
    opacity: .6;
}

/* ---- Dark theme touch-ups (Mazer toggles body.theme-dark) ---- */
body.theme-dark .chat-sidebar,
body.theme-dark .chat-main-header,
body.theme-dark .chat-input {
    border-color: rgba(255, 255, 255, .08);
}

body.theme-dark .chat-search input,
body.theme-dark .chat-input textarea {
    background: rgba(255, 255, 255, .05);
    border-color: rgba(255, 255, 255, .1);
    color: #e9ecef;
}

body.theme-dark .chat-messages {
    background: rgba(255, 255, 255, .015);
}

body.theme-dark .chat-conv-item:hover {
    background: rgba(255, 255, 255, .04);
}

body.theme-dark .chat-conv-item.active {
    background: rgba(255, 255, 255, .06);
}

body.theme-dark .chat-date-divider span,
body.theme-dark .chat-system span {
    background: rgba(255, 255, 255, .08);
}
