/**
 * Meetgle Messages Modal — flat Stage-themed design, matched to the chat-history /
 * notifications modals. Surface #141417 (same as the leaderboard modal). Inbox =
 * floating conversation cards; DM thread = gold own / flat other bubbles. Header
 * uses the shared .mg-mtitle / .mg-mclose primitives (profile-modal.css).
 * Modal width/height (max-width 700 / max-height 90vh / view heights) are UNCHANGED.
 */

@keyframes messagesSpin { to { transform: rotate(360deg); } }
@keyframes msgRise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* scrollbar hiding */
.messages-modal-content,
.messages-container,
.messages-chat-container { scrollbar-width: none; -ms-overflow-style: none; }
.messages-modal-content::-webkit-scrollbar,
.messages-container::-webkit-scrollbar,
.messages-chat-container::-webkit-scrollbar { display: none; }

/* Modal content — sizing UNCHANGED */
.messages-modal-content {
    max-width: 700px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ============ INBOX ============ */
.messages-header { padding: 20px 24px 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* inbox scroll container — height UNCHANGED */
.messages-container { max-height: calc(80vh - 80px); overflow-y: auto; flex: 1; padding: 16px 24px 24px; }

/* loading */
.messages-loading { text-align: center; padding: 48px 0; }
.messages-loading p { color: rgba(255,255,255,0.35); font-size: 13px; margin: 12px 0 0; }
.messages-spinner { width: 32px; height: 32px; border: 3px solid rgba(255,255,255,0.1); border-top-color: rgba(255,255,255,0.5); border-radius: 50%; animation: messagesSpin 0.8s linear infinite; margin: 0 auto; }

/* empty state (flat 66px icon; wrapper #conversationsEmpty toggled block by JS) */
.msg-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 54px 24px 46px; gap: 16px; animation: msgRise .4s ease both; }
.msg-empty-ic { width: 66px; height: 66px; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.07); color: rgba(255,255,255,0.6); }
.msg-empty-ic svg { width: 30px; height: 30px; }
.msg-empty-msg { font-size: 15.5px; font-weight: 700; color: rgba(255,255,255,0.72); }
.msg-empty-sub { font-size: 12.5px; color: rgba(255,255,255,0.4); max-width: 250px; line-height: 1.45; }

/* conversation cards (floating, like .ch-history-item) */
.conversations-list { display: flex; flex-direction: column; gap: 8px; }
.conversation-item {
    display: flex; align-items: center; gap: 13px; padding: 11px 13px; cursor: pointer; border-radius: 16px;
    border: 1px solid rgba(255,255,255,0.07); background: rgba(255,255,255,0.04);
    transition: transform .16s, border-color .16s, background .16s; animation: msgRise .4s ease both;
}
.conversation-item:hover { transform: translateY(-2px); border-color: rgba(255,255,255,0.15); background: rgba(255,255,255,0.07); }
.conversation-item.unread { border-color: rgba(255,200,61,0.28); background: rgba(255,200,61,0.05); }
.conversation-item.unread:hover { border-color: rgba(255,200,61,0.42); background: rgba(255,200,61,0.08); }
.conversation-avatar { width: 46px; height: 46px; border-radius: 50% !important; object-fit: cover; flex-shrink: 0; border: 2px solid rgba(255,255,255,0.10); transition: border-color .16s; }
.conversation-item:hover .conversation-avatar { border-color: rgba(255,255,255,0.22); }
.conversation-content { flex: 1; min-width: 0; }
.conversation-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 3px; }
.conversation-name { font-size: 15px; font-weight: 700; color: #fff; display: inline-flex; align-items: center; gap: 5px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation-time { font-size: 11.5px; color: rgba(255,255,255,0.4); flex-shrink: 0; }
.conversation-preview { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.conversation-message { font-size: 12.5px; color: rgba(255,255,255,0.45); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.conversation-item.unread .conversation-message { color: rgba(255,255,255,0.75); font-weight: 500; }
.conversation-unread { background: #ffc83d; color: #000; font-size: 10px; font-weight: 800; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; display: grid; place-items: center; flex-shrink: 0; }

/* verification badge (gradient gold/blue tier — kept separate per design system; JS inline-styles it) */
.verification-badge { font-size: 12px; }

/* ============ CHAT VIEW / DM THREAD ============ */
#messagesChatView { flex-direction: column; height: 100%; max-height: 85vh; }

.messages-chat-header { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid rgba(255,255,255,0.08); flex-shrink: 0; }
/* back btn — mirrors .mg-mclose's !important guards so theme/Elementor button
   rules can't distort it into a padded rounded-rectangle (matches the close btn). */
.messages-back-btn {
    flex-shrink: 0;
    width: 32px !important;
    height: 32px !important;
    min-width: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    border-radius: 50% !important;
    background: rgba(255,255,255,0.1) !important;
    color: #fff !important;
    box-shadow: none !important;
    cursor: pointer;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: background 0.2s;
}
.messages-back-btn:hover,
.messages-back-btn:focus { background: rgba(255,255,255,0.2) !important; color: #fff !important; }
.messages-back-btn svg { width: 17px !important; height: 17px !important; display: block !important; }
.messages-chat-user { display: flex; align-items: center; gap: 10px; cursor: pointer; flex: 1; min-width: 0; }
.messages-chat-avatar { width: 38px; height: 38px; border-radius: 50% !important; object-fit: cover; border: 2px solid rgba(255,255,255,0.12); flex-shrink: 0; }
.messages-chat-user-info { display: flex; align-items: center; gap: 6px; min-width: 0; }
.messages-chat-username { color: #fff; font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.messages-chat-verification { font-size: 14px; display: inline-flex; }

/* messages container — height UNCHANGED */
.messages-chat-container { flex: 1; overflow-y: auto; padding: 16px 18px; min-height: 300px; max-height: calc(85vh - 200px); }
.chat-messages-list { display: flex; flex-direction: column; gap: 8px; }

/* bubbles */
.chat-message { display: flex; max-width: 80%; }
.chat-message.own { margin-left: auto; justify-content: flex-end; }
.chat-message.other { margin-right: auto; justify-content: flex-start; }
.chat-message-bubble { padding: 10px 14px; border-radius: 18px; position: relative; max-width: 100%; word-wrap: break-word; }
.chat-message.own .chat-message-bubble { background: #ffc83d; color: #000; border-bottom-right-radius: 6px; }
.chat-message.other .chat-message-bubble { background: rgba(255,255,255,0.06); color: #fff; border: 1px solid rgba(255,255,255,0.07); border-bottom-left-radius: 6px; }
.chat-message-text { font-size: 14px; line-height: 1.4; display: block; }
.chat-message-photo { max-width: 200px; max-height: 220px; border-radius: 12px; cursor: pointer; display: block; }
.chat-message-time { font-size: 10px; opacity: 0.6; display: block; margin-top: 4px; text-align: right; }
.chat-message.other .chat-message-time { color: rgba(255,255,255,0.35); text-align: left; opacity: 1; }

/* spark transfer — centered gold status pill */
.chat-message.spark-transfer { display: flex; justify-content: center; padding: 4px 0; max-width: 100%; }
.chat-message.spark-transfer .chat-message-bubble { background: rgba(255,200,61,0.10); border: 1px solid rgba(255,200,61,0.25); border-radius: 14px; padding: 8px 14px; display: inline-flex; align-items: center; gap: 8px; color: #ffc83d; font-size: 13px; font-weight: 700; }
.chat-message.spark-transfer .chat-message-bubble svg { width: 14px; height: 14px; flex-shrink: 0; }
.chat-message.spark-transfer .chat-message-time { font-size: 10px; color: rgba(255,200,61,0.6); margin-left: 4px; font-weight: 500; opacity: 1; margin-top: 0; }

/* ============ COMPOSER ============ */
.messages-input-container { padding: 12px 18px 16px; border-top: 1px solid rgba(255,255,255,0.08); flex-shrink: 0; }
.messages-cost-indicator { text-align: center; font-size: 11.5px; color: rgba(255,255,255,0.35); margin-bottom: 10px; display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap; }
.messages-cost-indicator.premium { color: #36d399; font-weight: 600; }
.messages-balance-display { color: #ffc83d; font-weight: 700; }
.messages-input-row { display: flex; align-items: center; gap: 8px; }

.messages-photo-btn { background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.08); border-radius: 50%; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; cursor: pointer; color: rgba(255,255,255,0.5); transition: background .16s, color .16s; flex-shrink: 0; }
.messages-photo-btn:hover { background: rgba(255,255,255,0.1); color: rgba(255,255,255,0.8); }

/* sparks btn — defensive !important guards beat themed/Elementor button rules */
.messages-sparks-btn {
    background: rgba(255,200,61,0.1) !important;
    border: 1px solid rgba(255,200,61,0.22) !important;
    border-radius: 50% !important;
    width: 40px !important; height: 40px !important;
    min-width: 40px !important; min-height: 40px !important;
    max-width: 40px !important; max-height: 40px !important;
    display: flex !important; align-items: center !important; justify-content: center !important;
    cursor: pointer !important; color: #ffc83d !important; transition: all 0.2s !important; flex-shrink: 0 !important;
    padding: 0 !important; margin: 0 !important; font-family: inherit !important; box-shadow: none !important;
    outline: none !important; text-transform: none !important; letter-spacing: normal !important; line-height: 1 !important;
    -webkit-appearance: none !important; appearance: none !important; -webkit-tap-highlight-color: transparent !important;
}
.messages-sparks-btn:hover { background: rgba(255,200,61,0.18) !important; border-color: rgba(255,200,61,0.35) !important; transform: scale(1.05) !important; }
.messages-sparks-btn:active { transform: scale(0.95) !important; }
.messages-sparks-btn:focus { outline: none !important; box-shadow: none !important; }
.messages-sparks-btn svg { width: 18px !important; height: 18px !important; min-width: 18px !important; min-height: 18px !important; display: block !important; color: #ffc83d !important; fill: #ffc83d !important; }

.messages-text-input { flex: 1; background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1); border-radius: 20px; padding: 10px 16px; font-size: 14px; color: #fff; outline: none; transition: border-color .16s; }
.messages-text-input:focus { border-color: rgba(255,200,61,0.4); }
.messages-text-input::placeholder { color: rgba(255,255,255,0.3); }

.messages-send-btn { background: #ffc83d; border: none; border-radius: 50%; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; cursor: pointer; color: #000; transition: transform .16s, background .16s, opacity .16s; flex-shrink: 0; }
.messages-send-btn:hover { transform: scale(1.05); background: #e6ad2e; }
.messages-send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* external envelope badge (topbar source; hidden on Stage) */
.messages-envelope-badge {
    position: absolute; top: -4px; right: -4px; background: #EF4444; color: #fff; font-size: 10px; font-weight: 600;
    min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
    border: 2px solid #141417;
}

/* ============ Mobile fullscreen (PRESERVED — width/height unchanged) ============ */
@media (max-width: 900px) {
    #messagesModal { padding: 0 !important; }
    #messagesModal > .messages-modal-content {
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100vh !important;
        height: 100svh !important;
        max-height: 100vh !important;
        max-height: 100svh !important;
        border-radius: 0 !important;
    }
    .messages-header { padding: 18px 16px 0; }
    .messages-container { max-height: calc(100svh - 80px) !important; padding: 14px 16px 20px; }
    #messagesChatView { max-height: 100svh !important; }
    .messages-chat-container { max-height: calc(100svh - 180px) !important; }
    .chat-message { max-width: 85%; }
    .chat-message-photo { max-width: 180px; }
}
