/* MESSAGES SYSTEM - PREMIUM UI */

.messages-app-container {
    height: calc(100vh - 7rem);
    background: #fff;
    border-radius: 24px;
    border: 1px solid var(--c-card-border);
    display: flex;
    overflow: hidden;
    box-shadow: var(--shadow-soft);
}

/* LEFT PANEL - CONTACTS */
.msg-contacts-panel {
    width: 320px;
    border-right: 1px solid #f1f5f9;
    display: flex;
    flex-direction: column;
    background: #fff;
    flex-shrink: 0;
}

.contacts-header {
    padding: 1.5rem;
    border-bottom: 1px solid #f1f5f9;
}

.contacts-list {
    flex-grow: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.contact-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    color: inherit;
    margin-bottom: 4px;
}

.contact-item:hover {
    background: #f8fafc;
}

.contact-item.active {
    background: var(--c-accent-soft);
    color: var(--c-accent);
}

.contact-avatar-wrap {
    position: relative;
    width: 48px;
    height: 48px;
    flex-shrink: 0;
}

.contact-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.contact-info {
    flex-grow: 1;
    min-width: 0;
}

.contact-name {
    font-weight: 700;
    font-size: 0.95rem;
    margin-bottom: 2px;
}

.contact-last-msg {
    font-size: 0.8rem;
    color: var(--c-text-sec);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* RIGHT PANEL - CHAT */
.msg-chat-panel {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background: #f8fafc;
    min-width: 0;
}

@media (max-width: 992px) {
    .messages-app-container {
        height: calc(100vh - 6rem);
        border-radius: 16px;
    }

    .msg-contacts-panel {
        width: 100%;
        border-right: none;
    }

    .msg-chat-panel {
        display: none;
    }

    .messages-app-container.show-chat .msg-contacts-panel {
        display: none;
    }

    .messages-app-container.show-chat .msg-chat-panel {
        display: flex;
        width: 100%;
    }

    .chat-body {
        padding: 1rem;
    }
}

.chat-header {
    padding: 1rem 1.5rem;
    background: #fff;
    border-bottom: 1px solid #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-body {
    flex-grow: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* BUBBLES */
.message-bubble {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.msg-text {
    font-size: 0.95rem;
    line-height: 1.5;
    word-break: break-word;
    /* Ensure long words don't break layout */
    white-space: pre-line;
    /* Preserve line breaks from DB */
}

.msg-sent {
    align-self: flex-end;
    background: var(--c-accent);
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 12px rgba(30, 58, 138, 0.15);
}

.msg-received {
    align-self: flex-start;
    background: #fff;
    color: var(--c-text-main);
    border-bottom-left-radius: 4px;
    border: 1px solid #e2e8f0;
}

.msg-time {
    font-size: 0.65rem;
    margin-top: 4px;
    opacity: 0.7;
    text-align: right;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.msg-actions {
    opacity: 0;
    transition: opacity 0.2s;
}

.message-bubble:hover .msg-actions {
    opacity: 1;
}

.btn-delete-msg {
    background: none;
    border: none;
    color: inherit;
    padding: 0;
    font-size: 0.8rem;
    cursor: pointer;
    margin-left: 8px;
}

.btn-delete-msg:hover {
    color: var(--c-danger);
}

.btn-delete-conv {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid #fee2e2;
    color: var(--c-danger);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-delete-conv:hover {
    background: var(--c-danger);
    color: #fff;
    transform: scale(1.1);
}

/* FOOTER - INPUT */
.chat-footer {
    padding: 1.25rem 1.5rem;
    background: #fff;
    border-top: 1px solid #f1f5f9;
}

.chat-input-group {
    background: #f1f5f9;
    padding: 6px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-input {
    flex-grow: 1;
    min-width: 0;
    border: none;
    background: transparent;
    padding: 10px 12px;
    font-size: 0.9rem;
    outline: none;
    resize: none;
    line-height: 1.4;
    max-height: 150px;
    overflow-y: hidden;
}

.btn-send-msg {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--c-accent);
    color: #fff;
    border: none;
    display: flex !important;
    /* Force visibility */
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    flex-shrink: 0;
    /* Don't squash on mobile */
}

.btn-send-msg:hover {
    transform: scale(1.05);
}

/* UTILS */
.empty-chat-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--c-text-sec);
    text-align: center;
}

/* REACTIONS & REPLIES UI */
.msg-reactions-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
}

.reaction-pill {
    background: #fff;
    border: 1px solid #e2e8f0;
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 99px;
    display: flex;
    align-items: center;
    gap: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.reaction-pill.active {
    background: var(--c-accent-soft);
    border-color: var(--c-accent);
}

.reaction-trigger-wrap {
    position: relative;
}

.reaction-popover {
    position: absolute;
    bottom: 100%;
    left: 0;
    background: #fff;
    border-radius: 99px;
    padding: 4px 12px;
    display: none;
    gap: 6px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    border: 1px solid #e2e8f0;
    z-index: 100;
    margin-bottom: 8px;
    white-space: nowrap;
}

/* Align right for sent messages to prevent overflow */
.msg-sent .reaction-popover {
    left: auto;
    right: 0;
}

/* Ensure it stays within bubble for received too if needed */
.msg-received .reaction-popover {
    left: 0;
    right: auto;
}

.reaction-popover.show {
    display: flex;
}

.react-btn {
    border: none;
    background: none;
    font-size: 1.2rem;
    padding: 2px;
    cursor: pointer;
    transition: transform 0.1s;
}

.react-btn:hover {
    transform: scale(1.3);
}

/* Reply Styling */
.reply-preview {
    background: rgba(0, 0, 0, 0.05);
    border-left: 3px solid var(--c-accent);
    padding: 6px 10px;
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 0.8rem;
}

.reply-box-ui {
    padding: 10px 1.5rem;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
    display: none;
    justify-content: space-between;
    align-items: flex-start;
}

.reply-box-ui.active {
    display: flex;
}

/* EMOJI PICKER FOR INPUT */
.emoji-picker-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.emoji-picker-popover {
    position: absolute;
    bottom: calc(100% + 15px);
    right: 0;
    background: #ffffff;
    border-radius: 20px;
    padding: 15px;
    display: none;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.15);
    border: 1px solid #f1f5f9;
    z-index: 1000;
    width: 250px;
    max-height: 280px;
    overflow-y: auto;
    overflow-x: hidden;
    transition: all 0.2s ease;
}

.emoji-picker-popover::-webkit-scrollbar {
    width: 4px;
}

.emoji-picker-popover::-webkit-scrollbar-thumb {
    background: #e2e8f0;
    border-radius: 10px;
}

.emoji-picker-popover.show {
    display: grid;
    animation: emojiEnter 0.3s ease-out;
}

@keyframes emojiEnter {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Picker Header */
.emoji-picker-popover::before {
    content: "Emojis";
    grid-column: span 6;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--c-text-sec);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid #f1f5f9;
}

.emoji-item {
    font-size: 1.2rem;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 10px;
    transition: all 0.15s ease;
    background: #f8fafc;
}

.emoji-item:hover {
    background: var(--c-accent-soft);
    transform: scale(1.1);
}

.emoji-item:active {
    transform: scale(0.95);
}

/* REFINE INPUT ICONS */
.chat-input-group label,
.chat-input-group button {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* LARGE EMOJIS */
.message-bubble.msg-only-emoji {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
}

.text-only-emoji {
    font-size: 3.5rem !important;
    line-height: 1 !important;
    display: block;
}

.msg-only-emoji .msg-time {
    color: var(--c-text-sec);
    justify-content: flex-end;
}

/* ATTACHMENT PREVIEW */
.attachment-preview-box {
    padding: 10px 1.5rem;
    background: #f8fafc;
    border-top: 1px solid #f1f5f9;
    display: none;
    /* Hidden by default */
}

.attachment-preview-box.active {
    display: block;
}

/* IMAGE LIGHTBOX */
.chat-img-clickable {
    cursor: zoom-in;
    transition: filter 0.2s;
}

.chat-img-clickable:hover {
    filter: brightness(0.9);
}

#lightboxModal .modal-content {
    background: transparent;
    border: none;
}

#lightboxModal .modal-body {
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

.lightbox-img {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 12px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
}

/* DOWNLOAD ACTION */
.lightbox-actions {
    position: absolute;
    bottom: -50px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 15px;
}

.btn-download-premium {
    background: #fff;
    color: var(--c-text-main);
    border-radius: 99px;
    padding: 10px 25px;
    font-weight: 700;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    transition: all 0.2s;
}

.btn-download-premium:hover {
    background: var(--c-accent);
    color: #fff;
    transform: translateY(-2px);
}

/* MULTI-IMAGE GALLERY */
.msg-gallery {
    display: grid;
    gap: 4px;
    max-width: 320px;
}

.msg-gallery.g-1 {
    grid-template-columns: 1fr;
}

.msg-gallery.g-2 {
    grid-template-columns: 1fr 1fr;
}

.msg-gallery.g-3 {
    grid-template-columns: 1fr 1fr;
}

.msg-gallery.g-3 .gallery-item:first-child {
    grid-row: span 2;
}

.msg-gallery.g-4 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    min-height: 120px;
    max-height: 180px;
}

.g-1 .gallery-item img {
    max-height: 280px;
}

/* PREVIEW GRID */
#previewGrid img {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

/* MULTI-ATTACHMENT PREVIEW */
#previewContainer img {
    border: 2px solid #fff;
    transition: transform 0.2s;
}

#previewContainer img:hover {
    transform: scale(1.05);
}

/* DOC ATTACHMENT STYLE */
.msg-doc-pill {
    background: #fff;
    border: 1px solid #e2e8f0;
    padding: 10px 15px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-decoration: none !important;
    color: var(--c-text-main) !important;
    transition: all 0.2s;
    font-weight: 600;
    max-width: 100%;
}

.msg-sent .msg-doc-pill {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
    color: #fff !important;
}

.msg-doc-pill:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}