/* Messaging - for i nbox Page =========================== */

:root {
    --msg-primary: #026181;
    --msg-primary-dark: #015370;
    --msg-surface: #ffffff;
    --msg-surface-soft: #eff5f9;
    --msg-border: #d4e2ed;
    --msg-text: #111827;
    --msg-muted: #8a94ab;
    --msg-received: #ffffff;
    --msg-sent-start: #026181;
    --msg-sent-end: #0288b3;
}

.messaging-page {
    max-width: 720px;
    margin: 2rem auto;
    padding: 0 1rem;
}

.messaging-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}

.messaging-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--msg-text);
    margin: 0;
}

/* Conversation List */
.conversation-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    border-radius: 12px;
    overflow: hidden;
    background: var(--msg-surface-soft);
    border: 1px solid var(--msg-border);
    box-shadow: 0 12px 22px rgba(30, 41, 59, 0.08);
}

.conversation-item {
    background: rgba(255, 255, 255, 0.88);
    border: 1px solid transparent;
    transition: background 0.15s ease;
}

.conversation-item:hover {
    background: #fff;
    border-color: #c8dceb;
}

.conversation-item.unread {
    background: #e2f0f6;
}

.conversation-item.unread:hover {
    background: #dcecf5;
}

.conversation-item a {
    display: flex;
    align-items: center;
    padding: 14px 18px;
    text-decoration: none;
    color: inherit;
    gap: 14px;
}

/* Avatar */
.conversation-avatar {
    flex-shrink: 0;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    overflow: hidden;
    background: #d4e4ef;
}

.conversation-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Info Section */
.conversation-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.conversation-top-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.conversation-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--msg-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-time {
    font-size: 0.75rem;
    color: var(--msg-muted);
    white-space: nowrap;
    flex-shrink: 0;
    margin-left: 8px;
}

.unread .conversation-time {
    color: var(--msg-primary);
    font-weight: 600;
}

.conversation-bottom-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.conversation-preview {
    font-size: 0.85rem;
    color: #4b5563;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.conversation-preview.empty {
    font-style: italic;
    color: var(--msg-muted);
}

.unread .conversation-preview {
    color: #374151;
    font-weight: 500;
}

/* Unread Badge */
.unread-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--msg-primary), var(--msg-sent-end));
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-left: 8px;
}

/* Empty State */
.no-conversations {
    text-align: center;
    padding: 4rem 2rem;
    color: #9ca3af;
}

.no-conversations i {
    font-size: 3rem;
    margin-bottom: 1rem;
    color: #d1d5db;
}

.no-conversations p {
    font-size: 1.1rem;
    font-weight: 600;
    color: #6b7280;
    margin: 0 0 0.5rem;
}

.no-conversations span {
    font-size: 0.9rem;
}


/* ===========================
   Messaging - Thread Page
   =========================== */

.thread-page {
    max-width: 720px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 70px);
    /* 70px approx navbar height */
    background: linear-gradient(180deg, #f0f4ff 0%, #f7f9ff 100%);
}

/* Thread Header */
.thread-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    background: linear-gradient(180deg, #ffffff 0%, #f8faff 100%);
    border-bottom: 1px solid var(--msg-border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.back-btn {
    display: flex;
}

/* Presence Indicator */
.presence-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-right: 4px;
}

.presence-dot.online {
    background: #026181;
    box-shadow: 0 0 0 2px rgba(2, 97, 129, 0.25);
    animation: presence-pulse 2s ease-in-out infinite;
}

.presence-dot.offline {
    background: #94a3b8;
}

@keyframes presence-pulse {

    0%,
    100% {
        box-shadow: 0 0 0 2px rgba(2, 97, 129, 0.25);
    }

    50% {
        box-shadow: 0 0 0 5px rgba(2, 97, 129, 0.0);
    }
}

.back-btn {

    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    color: #374151;
    text-decoration: none;
    transition: background 0.15s;
}

.back-btn:hover {
    background: #f3f4f6;
}

.thread-user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: inherit;
}

.thread-user-info:hover .thread-user-name {
    color: var(--msg-primary);
}

.thread-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: #d4e4ef;
}

.thread-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.thread-user-name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--msg-text);
    display: flex;
    flex-direction: column;
    transition: color 0.15s;
}

.user-type-label {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--msg-muted);
}

/* Messages Container */
.thread-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 18px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: #DFEEF6;
}

/* Loading Indicator */
.message-loading-indicator {
    text-align: center;
    padding: 12px 0;
    margin-bottom: 12px;
}

.message-loading-indicator span {
    font-size: 0.78rem;
    color: var(--msg-muted);
    background: rgba(255, 255, 255, 0.8);
    padding: 6px 14px;
    border-radius: 16px;
    border: 1px solid var(--msg-border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

/* Message Bubbles */
.message-bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 16px;
    word-wrap: break-word;
    position: relative;
    overflow: visible;
}

.message-bubble.has-media {
    padding: 3px;
    border-radius: 12px;
    width: fit-content;
    max-width: 100%;
}

.message-bubble.has-media.sent {
    border-bottom-right-radius: 4px;
}

.message-bubble.has-media.received {
    border-bottom-left-radius: 4px;
}

.message-bubble.has-media .message-meta {
    position: absolute;
    bottom: 4px;
    right: 6px;
    background: rgba(0,0,0,0.35);
    color: #fff;
    padding: 1px 6px;
    border-radius: 6px;
    margin-top: 0;
    z-index: 2;
}

.message-bubble.has-media .message-status {
    color: #fff;
}

.message-bubble.deleted {
    opacity: 0.55;
}

.message-bubble.deleted .message-body {
    font-style: italic;
    padding: 0;
}

.message-bubble.sent {
    align-self: flex-end;
    background: linear-gradient(145deg, var(--msg-sent-start), var(--msg-sent-end));
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 10px 20px rgba(2, 97, 129, 0.24);
}

.message-bubble.received {
    align-self: flex-start;
    background: var(--msg-received);
    color: var(--msg-text);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--msg-border);
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.07);
}

.message-body {
    font-size: 0.9rem;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: break-word;
    position: relative;
    z-index: 1;
}

.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 2px;
    color: #fff;
    position: relative;
    z-index: 2;
}

.message-bubble.received:not(.has-media) .message-meta {
    color: rgba(0, 0, 0, 0.8);
}

/* === Reply-inline styles (popup) === */
.message-bubble.has-inline-reply {
    background: transparent !important;
    padding: 0;
    border: none !important;
    box-shadow: none !important;
    cursor: pointer;
}

.reply-inline {
    display: flex;
    flex-direction: column;
    gap: 4px;
    white-space: normal;
}

.reply-inline-label {
    font-size: 0.68rem;
    line-height: 1.2;
    color: #6b7280;
    padding: 0 2px;
}

.reply-inline-quote {
    position: relative;
    z-index: 2;
    font-size: 0.78rem;
    line-height: 1.35;
    padding: 6px 8px;
    border-radius: 10px;
    background: #e5e7eb;
    color: #374151;
    word-break: break-word;
    overflow-wrap: break-word;
    cursor: pointer;
    min-height: 40px;
    transition: background 0.15s ease;
}

.reply-inline-quote:hover {
    background: #d1d5db;
}

.reply-quote-media-thumb {
    display: inline-block;
    width: 40px;
    height: 40px;
    border-radius: 6px;
    overflow: hidden;
    position: relative;
    vertical-align: middle;
    background: #d1d5db;
}

.reply-quote-media-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.reply-quote-media-play {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 10px;
    background: rgba(0, 0, 0, 0.25);
}

.reply-quote-media-file {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 6px;
    background: #d1d5db;
    color: #6b7280;
    font-size: 18px;
}

.popup-reply-context-thumb {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    overflow: hidden;
    position: relative;
    background: #e5e7eb;
}

.popup-reply-context-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.popup-reply-context-thumb-play {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 10px;
    background: rgba(0, 0, 0, 0.25);
}

.popup-reply-context-thumb-file {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6b7280;
    font-size: 16px;
}

.reply-inline-main {
    padding: 10px 14px;
    border-radius: 16px;
    cursor: default;
}

.reply-inline-text {
    position: relative;
    z-index: 2;
    font-size: 0.9rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: break-word;
}

.message-bubble.sent.has-inline-reply .reply-inline-main {
    background: linear-gradient(145deg, var(--msg-sent-start), var(--msg-sent-end));
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 10px 20px rgba(2, 97, 129, 0.24);
}

.message-bubble.received.has-inline-reply .reply-inline-main {
    background: var(--msg-received);
    color: var(--msg-text);
    border-bottom-left-radius: 4px;
    border: none;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.07);
}

.message-bubble.has-inline-reply .message-meta {
    margin-top: 4px;
}

/* === Popup reply button === */
.message-bubble {
    position: relative;
}

.popup-reply-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.85);
    color: #6b7280;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    opacity: 0;
    transition: opacity 0.15s ease, background 0.15s ease;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
    z-index: 2;
}

.message-bubble.sent .popup-reply-btn {
    left: -30px;
}

.message-bubble.received .popup-reply-btn {
    right: -30px;
}

.message-bubble:hover .popup-reply-btn,
.popup-reply-btn:hover {
    opacity: 1;
}

.popup-reply-btn:hover {
    background: #f3f4f6;
    color: #026181;
}

/* ===== MESSAGE OPTIONS (3-DOTS) ===== */
.message-options-container {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    right: -62px;
    z-index: 20;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.message-bubble.sent .message-options-container {
    right: auto;
    left: -62px;
}

.message-bubble.show-options .message-options-container {
    opacity: 1;
    pointer-events: all;
}

/* Extend hover hit area to include options button zone (WhatsApp style) */
.message-bubble.received::before {
    content: '';
    position: absolute;
    top: -4px;
    bottom: -4px;
    right: -120px;
    left: 0;
    pointer-events: auto;
}

.message-bubble.sent::before {
    content: '';
    position: absolute;
    top: -4px;
    bottom: -4px;
    left: -120px;
    right: 0;
    pointer-events: auto;
}

.message-options-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(6px);
    color: #64748b;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    transition: all 0.15s ease;
}

.message-options-btn:hover {
    background: #fff;
    color: var(--primary-blue, #026181);
    box-shadow: 0 4px 14px rgba(2, 97, 129, 0.2);
    transform: scale(1.08);
}

.message-options-menu {
    position: absolute;
    top: 32px;
    right: 0;
    min-width: 150px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);
    overflow: hidden;
    z-index: 200;
    animation: menuFadeIn 0.15s ease;
}

.message-bubble.sent .message-options-menu {
    right: auto;
    left: 0;
}

@keyframes menuFadeIn {
    from { opacity: 0; transform: translateY(-6px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.message-options-menu.hidden {
    display: none;
}

.option-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 9px 14px;
    font-size: 0.83rem;
    font-weight: 500;
    color: #374151;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    transition: background 0.12s;
}

.option-item:hover {
    background: #eef6fb;
    color: var(--primary-blue, #026181);
}

.option-item.delete-msg-btn:hover {
    background: #fff1f2;
    color: #e11d48;
}

.option-item i {
    width: 14px;
    text-align: center;
    flex-shrink: 0;
}

.message-edited-tag {
    font-size: 0.68rem;
    opacity: 0.65;
    font-style: italic;
    margin-right: 4px;
}

/* === Popup reply context bar === */
.popup-reply-context {
    display: none;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 12px;
    background: linear-gradient(180deg, #e6f4f9 0%, #dcecf5 100%);
    border-left: 3px solid #026181;
    border-radius: 8px 8px 0 0;
    margin: 4px 8px 0;
}

.popup-reply-context-content {
    flex: 1;
    min-width: 0;
}

.popup-reply-context-title {
    font-size: 0.72rem;
    font-weight: 600;
    color: #026181;
}

.popup-reply-context-preview {
    font-size: 0.72rem;
    color: #6b7280;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.popup-reply-context-cancel {
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    color: #9ca3af;
    font-size: 1rem;
    line-height: 1;
    padding: 0 2px;
}

.popup-reply-context-cancel:hover {
    color: #ef4444;
}

/* ===== POPUP EDIT INDICATOR ===== */
.popup-edit-indicator {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: linear-gradient(to right, #e6f4f9, #eef6fb);
    border-left: 3px solid var(--primary-blue, #026181);
    border-radius: 8px 8px 0 0;
    font-size: 0.82rem;
    color: #026181;
}
.popup-edit-indicator i {
    margin-right: 2px;
}
.popup-edit-cancel-btn {
    margin-left: auto;
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    color: #9ca3af;
    line-height: 1;
    padding: 0 4px;
}
.popup-edit-cancel-btn:hover {
    color: #ef4444;
}

.message-time {
    font-size: 0.68rem;
}

.message-status {
    font-size: 0.7rem;
    opacity: 0.8;
    letter-spacing: -2px;
}

/* Highlight Flash Animation */
.highlight-flash {
    animation: flashHighlight 2.5s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    z-index: 5;
}

@keyframes flashHighlight {
    0% {
        filter: drop-shadow(0 0 15px rgba(250, 176, 5, 0.8)) brightness(1.15);
        transform: scale(1.05);
    }

    15% {
        filter: drop-shadow(0 0 10px rgba(250, 176, 5, 0.6)) brightness(1.05);
        transform: scale(1.03);
    }

    100% {
        filter: drop-shadow(0 0 0px rgba(250, 176, 5, 0)) brightness(1);
        transform: scale(1);
    }
}


.message-bubble.sent:not(.has-media) .message-time,
.message-bubble.sent:not(.has-media) .message-status {
    color: rgba(255, 255, 255, 0.8);
}

/* Date Separators */
.date-separator {
    text-align: center;
    margin: 16px 0 12px;
    font-size: 0.75rem;
    color: var(--msg-muted);
    font-weight: 500;
    position: relative;
}

/* No Messages State */
.no-messages-yet {
    text-align: center;
    padding: 3rem 1rem;
    color: #6b7280;
    margin: auto 0;
}

.no-messages-yet p {
    font-size: 1rem;
    margin: 0;
}

/* Input Area */
.thread-input-area {
    padding: 12px 18px;
    background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
    border-top: 1px solid var(--msg-border);
}

.message-form {
    display: flex;
    align-items: center;
    gap: 10px;
}

.message-form input[type="text"] {
    flex: 1;
    padding: 10px 16px;
    border: 1px solid var(--msg-border);
    border-radius: 24px;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
    background: #eef3fb;
}

.message-form input[type="text"]:focus {
    border-color: var(--msg-primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(2, 97, 129, 0.14);
}

/* Scroll to Bottom Button */
.scroll-bottom-btn {
    position: absolute;
    bottom: 85px;
    right: 25px;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: white;
    color: var(--msg-primary);
    border: 1px solid var(--msg-border);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 100;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0;
    transform: translateY(10px);
}

.scroll-bottom-btn.visible {
    display: flex;
    opacity: 1;
    transform: translateY(0);
}

.popup-chat-view.reply-active .scroll-bottom-btn.visible {
    bottom: 135px;
}


.scroll-bottom-btn:hover {
    background: var(--msg-primary);
    color: white;
    border-color: var(--msg-primary);
    transform: scale(1.1);
}

.scroll-bottom-btn i {
    font-size: 0.9rem;
}

.message-form button[type="submit"] {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--msg-primary), var(--msg-sent-end));
    color: #fff;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.15s, transform 0.1s;
    flex-shrink: 0;
}

.message-form button[type="submit"]:hover {
    background: linear-gradient(135deg, var(--msg-primary), var(--msg-primary-dark));
}

.message-form button[type="submit"]:active {
    transform: scale(0.95);
}


/* ===========================
   Navbar Message Badge
   =========================== */

.message-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #ef4444;
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    padding: 0 4px;
    margin-left: 4px;
    vertical-align: top;
}


/* ===========================
   Responsive
   =========================== */

/* ===========================
   Message Popup Modal
   =========================== */

#message-popup-container {
    position: fixed;
    bottom: 0px;
    /* Sits cleanly above the Sparks launcher */
    right: 10px;
    display: flex;
    flex-wrap: wrap-reverse;
    justify-content: flex-end;
    align-items: flex-end;
    gap: 12px;
    padding: 16px;
    max-width: min(100vw, 1100px);
    z-index: 2147483647;
    pointer-events: none;
}

.message-popup-modal {
    position: relative;
    width: min(340px, calc(100vw - 32px));
    height: min(450px, calc(100vh - 180px));
    /* Reduced height for better fit */
    min-height: 280px;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    border-radius: 22px;
    border: 1px solid var(--msg-border);
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.2);
    pointer-events: all;
    max-height: calc(100vh - 140px);
    overflow: hidden;
}

.message-popup-modal.dock-hidden {
    display: none;
}

.message-popup-dock.expanding {
    animation: dockExpandFromLauncher 0.24s cubic-bezier(0.2, 0.85, 0.24, 1);
    transform-origin: right bottom;
}

@keyframes dockExpandFromLauncher {
    from {
        transform: translate(8px, 14px) scale(0.2);
        opacity: 0.15;
        border-radius: 30px;
    }

    to {
        transform: translate(0, 0) scale(1);
        opacity: 1;
        border-radius: 22px;
    }
}

.message-popup-modal.minimized {
    height: 48px;
    width: 200px;
    /* Narrower and more compact */
    border-radius: 24px;
    box-shadow: 0 8px 20px rgba(2, 97, 129, 0.2);
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.message-popup-modal.minimized .popup-messages,
.message-popup-modal.minimized .popup-input {
    display: none;
}

.message-popup-modal.minimized .popup-content {
    display: none;
}

.message-popup-modal.minimized .popup-header {
    border-bottom: none;
    border-radius: 24px;
    padding: 0 16px;
    height: 100%;
    background: linear-gradient(135deg, #026181, #015370);
    color: white;
}

.message-popup-modal.minimized .popup-header h3 {
    font-size: 0.95rem;
    color: white;
}

.message-popup-modal.minimized .popup-back-btn {
    display: none;
}

.message-popup-modal.minimized .popup-btn {
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 0.75rem;
    padding: 0;
    min-width: 24px;
    min-height: 24px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.message-popup-modal.minimized .popup-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: linear-gradient(180deg, #ffffff 0%, #f8faff 100%);
    border-bottom: 1px solid var(--msg-border);
    gap: 12px;
    flex-shrink: 0;
    border-top-left-radius: 22px;
    border-top-right-radius: 22px;
}

.popup-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1;
}

.popup-user-info {
    flex: 1;
    min-width: 0;
}

.popup-user-name {
    display: block;
    font-size: 0.95rem;
    font-weight: 600;
    color: #1a1a1a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.popup-title-link {
    display: inline-block;
    font-size: 0.95rem;
    font-weight: 600;
    color: #1a1a1a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    text-decoration: none;
    transition: color 0.15s ease;
}

.popup-title-link:hover {
    color: #026181;
    text-decoration: underline;
}

.popup-user-status {
    font-size: 0.75rem;
    color: #64748b;
    display: flex;
    align-items: center;
    gap: 4px;
    line-height: 1;
    margin-top: 2px;
}

.popup-user-status.hidden {
    display: none;
}

.popup-controls {
    display: flex;
    gap: 4px;
}

.popup-back-btn.hidden,
.popup-conversation-list-view.hidden,
.popup-chat-view.hidden {
    display: none;
}

.popup-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--msg-border);
    border-radius: 10px;
    background: #ffffff;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.15s;
    font-size: 0.9rem;
}

.popup-btn:hover {
    background: #e6f4f9;
    color: #374151;
    border-color: #d1d5db;
}

.popup-btn:active {
    transform: scale(0.95);
}

.popup-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    overflow-anchor: none;
    overscroll-behavior: contain;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: #DFEEF6;
}

.popup-content {
    flex: 1;
    min-height: 0;
    display: flex;
    overflow: hidden;
}

.popup-conversation-list-view {
    flex: 1;
    min-height: 0;
    background: #e8f1f7;
}

.popup-list-content {
    height: 100%;
    width: 100%;
    box-sizing: border-box;
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
}

.popup-conversation-item {
    display: block;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
    border: 1px solid var(--msg-border);
    border-radius: 14px;
    background: #ffffff;
    padding: 10px;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.popup-conversation-item:hover {
    background: #eef6fa;
    border-color: #cadeec;
}

.popup-conversation-item.unread {
    border-color: #bcd4e8;
    background: #e2f0f6;
}

.popup-conversation-item.unread .popup-conversation-preview {
    color: #374151;
}

.popup-conversation-item.unread .popup-conversation-time {
    color: #4b5563;
}

.popup-conversation-main {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    width: 100%;
}

.popup-conversation-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.popup-conversation-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: #111827;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    width: 100%;
}

.popup-conversation-name-wrap {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}

.orbit-tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: #026181;
    background: #e0f0f8;
    border: 1px solid #b8d8ea;
    flex-shrink: 0;
}

.orbit-tag.orbit-tag-popup {
    font-size: 0.6rem;
    padding: 2px 6px;
}

.popup-conversation-time {
    font-size: 0.72rem;
    color: #6b7280;
    flex-shrink: 0;
}

.popup-conversation-preview {
    font-size: 0.8rem;
    color: #4b5563;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    width: 100%;
}

.popup-conversation-unread {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    border-radius: 999px;
    padding: 0 5px;
    font-size: 0.68rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--msg-primary), var(--msg-sent-end));
    color: #fff;
    flex-shrink: 0;
}

.popup-chat-view {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: #DFEEF6;
    position: relative;
}

.popup-chat-view.is-loading-messages .scroll-bottom-btn {
    display: none !important;
}

.popup-chat-view.is-loading-messages .popup-input {
    pointer-events: none;
    opacity: 0.6;
}

.popup-input {
    padding: 10px;
    background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
    border-top: 1px solid var(--msg-border);
    flex-shrink: 0;
}

.popup-input .message-form {
    display: flex;
    align-items: center;
    gap: 8px;
}

.popup-message-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--msg-border);
    border-radius: 999px;
    font-size: 0.85rem;
    color: #111827;
    outline: none;
    transition: border-color 0.2s;
}

.popup-message-input::placeholder {
    color: #9ca3af;
}

.popup-message-input:focus {
    border-color: var(--msg-primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(2, 97, 129, 0.14);
}

.popup-send-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--msg-primary), var(--msg-sent-end));
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
}

.popup-send-btn:hover {
    background: linear-gradient(135deg, var(--msg-primary), var(--msg-primary-dark));
}

.floating-message-launcher {
    position: fixed;
    right: 25px;
    bottom: 25px;
    padding: 12px 24px;
    border-radius: 30px;
    background: linear-gradient(135deg, #026181, #015370);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    cursor: pointer;
    z-index: 2147483647 !important;
    box-shadow: 0 4px 15px rgba(2, 97, 129, 0.3);
    transition: all 0.3s ease;
}

.floating-message-launcher:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 28px rgba(2, 97, 129, 0.4);
}

.floating-message-launcher:active {
    transform: translateY(0);
}

body:has(.post-detail-overlay.active) .floating-message-launcher,
body:has(.post-detail-overlay.active) #message-popup-container {
    z-index: 9999 !important;
}

.floating-message-label {
    display: none;
    font-size: 0.92rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    white-space: nowrap;
    color: #fff;
}

.floating-message-launcher.is-minimized {
    width: 120px;
    /* Stay compact */
    border-radius: 24px;
    justify-content: center;
    padding: 0 16px;
}

.floating-message-launcher.is-minimized .floating-message-label {
    display: inline-block;
}

.floating-message-launcher.is-minimized i {
    font-size: 1rem;
}

.floating-message-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    line-height: 1;
}

/* Loading spinner for popup */
.loading-spinner {
    text-align: center;
    padding: 2rem 1rem;
    color: #9ca3af;
    font-size: 0.9rem;
}

.error-message {
    text-align: center;
    padding: 2rem 1rem;
    color: #ef4444;
    font-size: 0.9rem;
}

/* === Popup Attachment Rendering === */
.popup-message-attachments {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 2px;
    position: relative;
    z-index: 1;
}

.message-bubble.has-media .popup-message-attachments {
    margin-top: 0;
}

.message-bubble.has-media .message-body:empty {
    display: none;
}

.popup-attachment-image-wrapper {
    border-radius: 12px;
    overflow: hidden;
    width: 100%;
    max-width: 400px;
    max-height: 400px;
}

.popup-attachment-image {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 12px;
}

.popup-attachment-video-wrapper {
    border-radius: 12px;
    overflow: hidden;
    width: 100%;
    max-width: 400px;
    max-height: 400px;
    position: relative;
    background: #000;
}

.popup-attachment-video-wrapper .feed-video-controls-left {
    bottom: 8px;
    left: 8px;
}

.popup-attachment-video-wrapper .feed-video-controls-right {
    bottom: 6px;
    right: 8px;
}

.popup-attachment-video-wrapper .feed-video-progress-container {
    position: absolute;
    bottom: 0;
    left: 0;
    margin-top: 0;
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
}

.popup-attachment-video {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 12px;
    background: #000;
}

.popup-attachment-file {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px 16px;
    border-radius: 8px;
    background: #e5e7eb;
    color: #374151;
    font-size: 0.78rem;
    text-decoration: none;
    transition: background 0.15s;
    min-width: 160px;
    max-width: 240px;
    overflow: hidden;
    word-break: break-all;
}

.popup-attachment-file:hover {
    background: #d1d5db;
    color: #111827;
}

.popup-attachment-file i {
    font-size: 14px;
    flex-shrink: 0;
}

.att-file-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Responsive for mobile */
@media (max-width: 768px) {
    #message-popup-container {
        bottom: 72px;
        padding: 12px;
        gap: 10px;
    }

    .message-popup-modal {
        width: min(340px, calc(100vw - 24px));
        height: min(500px, calc(100vh - 132px));
        max-height: calc(100vh - 132px);
    }

    .message-popup-modal.minimized {
        width: 180px;
        height: 44px;
    }

    .floating-message-launcher {
        right: 16px;
        bottom: 16px;
        width: 54px;
        height: 54px;
        padding: 0;
        justify-content: center;
    }

    .floating-message-launcher.is-minimized {
        width: 110px;
    }
}

/* ===== DELETE CONFIRM MODAL ===== */
.message-delete-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    z-index: 2147483647;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: modalOverlayIn 0.18s ease;
}

@keyframes modalOverlayIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(16px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.message-delete-modal {
    background: #fff;
    border-radius: 16px;
    padding: 28px 28px 20px;
    max-width: 360px;
    width: 90%;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.2);
    animation: modalSlideIn 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.message-delete-modal h3 {
    font-size: 1.05rem;
    font-weight: 700;
    color: #0f172a;
    margin: 0 0 8px;
}

.message-delete-modal p {
    font-size: 0.88rem;
    color: #64748b;
    margin: 0 0 20px;
}

.message-delete-modal-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message-delete-modal-actions button {
    padding: 10px 16px;
    border-radius: 9px;
    border: none;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-delete-me {
    background: #f1f5f9;
    color: #334155;
}

.btn-delete-me:hover {
    background: #e2e8f0;
    color: #0f172a;
}

.btn-delete-everyone {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #fff;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn-delete-everyone:hover {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(239, 68, 68, 0.4);
}

.btn-delete-cancel {
    background: transparent;
    color: #94a3b8;
    font-weight: 500;
}

.btn-delete-cancel:hover {
    color: #475569;
}

/* ===== OPTIONS MENU UPWARD (prevent bottom overflow) ===== */
.message-options-menu.upward {
    top: auto;
    bottom: 32px;
}

@media (max-width: 480px) {
    #message-popup-container {
        bottom: 66px;
        padding: 8px;
        gap: 8px;
    }

    .message-popup-modal {
        width: calc(100vw - 16px);
        height: min(460px, calc(100vh - 124px));
        max-height: calc(100vh - 124px);
        min-height: 280px;
        border-radius: 14px;
    }

    .message-popup-modal.minimized {
        width: 160px;
        height: 42px;
    }

    .floating-message-launcher {
        right: 12px;
        bottom: 12px;
    }
}