/* =========================
   LAYOUT CONTAINER
========================= */
.chat-container {
    display: flex;
    height: 80vh;
    background: #444753;
    border-radius: 8px 8px 0 0;
    overflow: hidden;
}

/* =========================
   LEFT SIDEBAR (FRIENDS)
========================= */
.people-list {
    max-width: 280px;
    background: #191919;
    color: #fff;
    display: flex;
    flex-direction: column;
}

.search {
    padding: 15px;
}

    .search input {
        width: 100%;
        padding: 10px;
        border: none;
        border-radius: 4px;
    }

.friend-list {
    list-style: none;
    margin: 0;
    padding: 0 15px 15px;
    overflow-y: auto;
}

.friend-item {
    display: flex;
    gap: 10px;
    padding: 10px;
    cursor: pointer;
    border-radius: 6px;
}

    .friend-item img {
        width: 40px;
        height: 40px;
        border-radius: 50%;
    }

    .friend-item.active,
    .friend-item.active:hover {
        background: rgba(255,255,255,0.05) !important;
        border-left: 4px solid #2B988F;
    }

        .friend-item.active .name {
            font-weight: 600;
        }



/* Online / Offline status */
.friend-list .status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

    /* Presence dot (pseudo-element so theme CSS can't break it) */
    .friend-list .status::before {
        content: "";
        width: 8px;
        height: 8px;
        border-radius: 50%;
        flex: 0 0 8px;
    }

    .friend-list .status.online::before {
        background: #28c76f;
    }

    .friend-list .status.offline::before {
        background: #ea5455;
    }

    .friend-list .status.not-connected::before {
        background: #6b7280;
    }

/* Non-friend sidebar item */
.friend-item.non-friend img {
    opacity: 0.7;
    border: 2px dashed #4b5563;
    border-radius: 50%;
}
.friend-item.non-friend .name {
    color: #d1d5db;
}
.friend-item.non-friend .status.not-connected {
    font-size: .7rem;
    color: #6b7280;
    font-style: italic;
}

/* Divider between non-friend and friends */
.friend-list-divider {
    list-style: none;
    font-size: .65rem;
    color: #4b5563;
    text-transform: uppercase;
    letter-spacing: .07em;
    padding: 8px 10px 4px;
    user-select: none;
}

/* Add Friend button in chat header */
.chat-add-friend-btn {
    margin-left: auto;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 13px;
    font-size: .78rem;
    font-weight: 600;
    border-radius: 7px;
    border: 1px solid #a7d8d5;
    background: #e6f4f3;
    color: #2B988F;
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
}
.chat-add-friend-btn:hover:not(:disabled) {
    background: #2B988F;
    color: #fff;
    border-color: #2B988F;
}
.chat-add-friend-btn.sent,
.chat-add-friend-btn:disabled {
    opacity: 0.7;
    cursor: default;
}
.chat-add-friend-btn.sent {
    background: #f0fdf4;
    color: #15803d;
    border-color: #bbf7d0;
    opacity: 1;
}

/* =========================
   CHAT PANEL
========================= */
.chat {
    flex: 1;
    background: #F2F5F8;
    display: flex;
    flex-direction: column;
}

.chat-header {
    padding: 8px;
    display: flex;
    gap: 10px;
    align-items: center;
    background: #fff;
    border-bottom: #f8f8f8 !important;
}

#chatHeaderAvatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    flex: 0 0 auto;
    border: 2px solid #F2F5F8;
}

/* =========================
   MESSAGE AREA
========================= */
.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

#messageList {
    list-style: none;
    margin: 0;
    padding: 0;
}

    #messageList > li {
        display: flex;
        flex-direction: column;
        margin-bottom: 12px;
        width: 100%;
    }

        #messageList > li:has(.message.me) {
            align-items: flex-end;
        }

        #messageList > li:has(.message.them) {
            align-items: flex-start;
        }

/* Message bubble */
.message {
    padding: 10px 14px;
    border-radius: 10px;
    flex: 1;
    min-width: 0;
    position: relative;
}

    .message.me {
        background: #86BB71;
        color: #fff;
    }

    .message.them {
        background: #94C2ED;
    }

    /* Bubble caret */
    .message.me::after {
        content: "";
        position: absolute;
        right: -8px;
        top: 16px;
        border: 8px solid transparent;
        border-left-color: #86BB71;
    }

    .message.them::after {
        content: "";
        position: absolute;
        left: -8px;
        top: 16px;
        border: 8px solid transparent;
        border-right-color: #94C2ED;
    }

/* Message meta */
.message-meta {
    font-size: 12px;
    margin-bottom: 4px;
    opacity: .6;
    display: flex;
}

#messageList > li:has(.message.me) .message-meta {
    justify-content: flex-end;
    text-align: right;
}

.message-name {
    font-weight: 600;
    margin-right: 6px;
}

/* =========================
   CHAT INPUT
========================= */
.chat-input textarea {
    border-radius: 20px;
}

.chat-input .material-icons {
    font-size: 20px;
    vertical-align: middle;
}

/* =========================
   CHAT SHIMMER LOADER
========================= */

.chat-shimmer {
    display: flex;
    height: 100%;
    animation: fadeIn .2s ease;
}

.shimmer-sidebar {
    width: 240px;
    padding: 20px;
    border-right: 1px solid #eee;
}

.shimmer-chat {
    flex: 1;
    padding: 20px;
}

.shimmer-line {
    height: 14px;
    border-radius: 6px;
    margin-bottom: 14px;
    background: linear-gradient(90deg, #eee 25%, #f5f5f5 50%, #eee 75%);
    background-size: 200% 100%;
    animation: shimmer 1.2s infinite;
}

.shimmer-bubble {
    width: 60%;
    height: 16px;
    border-radius: 12px;
    margin-bottom: 18px;
    background: linear-gradient(90deg, #eee 25%, #f5f5f5 50%, #eee 75%);
    background-size: 200% 100%;
    animation: shimmer 1.2s infinite;
}

    .shimmer-bubble.right {
        margin-left: auto;
        width: 45%;
    }

.w-60 {
    width: 60%;
}

.w-70 {
    width: 70%;
}

.w-80 {
    width: 80%;
}

.w-85 {
    width: 85%;
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}


/* ===============================
   MESSAGE NOTIFICATION BADGE
=============================== */

/* =========================
   DM BUBBLE ROW
========================= */
.dm-bubble-row {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    max-width: 70%;
}

#messageList > li:has(.message.me) .dm-bubble-row {
    flex-direction: row-reverse;
    margin-left: auto;
}

/* =========================
   MESSAGE HIGHLIGHT (search)
========================= */
.msg-highlight {
    animation: msgHighlight 2.5s ease forwards;
}
@keyframes msgHighlight {
    0%   { background: rgba(251,191,36,0.35); border-radius: 8px; }
    70%  { background: rgba(251,191,36,0.2);  border-radius: 8px; }
    100% { background: transparent; }
}
.msg-highlight .message {
    outline: 2px solid rgba(251,191,36,0.7);
    outline-offset: 2px;
    border-radius: 10px;
}

/* =========================
   SEARCH DROPDOWN
========================= */
.msg-search-dropdown {
    position: absolute; /* positioned via JS against body */
    background: #1e1e1e;
    border: 1px solid #333;
    border-radius: 8px;
    z-index: 99999;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    max-height: 320px;
    overflow-y: auto;
}
.msg-search-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    cursor: pointer;
    transition: background .1s;
    border-bottom: 1px solid #2a2a2a;
}
.msg-search-item:last-child { border-bottom: none; }
.msg-search-item:hover { background: rgba(255,255,255,0.06); }
.msg-search-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}
.msg-search-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.msg-search-user {
    font-size: 0.8rem;
    font-weight: 600;
    color: #e5e7eb;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.msg-search-snippet {
    font-size: 0.74rem;
    color: #9ca3af;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.msg-search-snippet mark {
    background: rgba(251,191,36,0.35);
    color: #fbbf24;
    border-radius: 2px;
    padding: 0 1px;
}
.msg-search-time {
    font-size: 0.65rem;
    color: #6b7280;
    white-space: nowrap;
    flex-shrink: 0;
}
.msg-search-empty {
    padding: 14px 12px;
    font-size: 0.8rem;
    color: #6b7280;
    text-align: center;
}

/* =========================
   MESSAGE NOTIFICATION BADGE
========================= */
.message-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: #e53935;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    border-radius: 999px;
    display: none; /* controlled by JS */
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* ==============================
   MOBILE HANDLE
============================== */
.mm-mobile-handle {
    display: none;
    flex-direction: column;
    align-items: center;
    padding: 10px 16px 0;
    flex-shrink: 0;
    background: #fff;
    border-radius: 20px 20px 0 0;
}

.mm-handle-bar {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: rgba(0,0,0,0.15);
    margin-bottom: 8px;
    flex-shrink: 0;
}

.mm-handle-inner {
    display: flex;
    align-items: center;
    width: 100%;
    padding-bottom: 8px;
}

.mm-handle-title {
    flex: 1;
    font-size: 0.95rem;
    font-weight: 600;
    color: #111;
}

/* Back button in chat header (shown on mobile when chat is open) */
.chat-back-btn {
    display: none;
    background: none;
    border: none;
    padding: 0 8px 0 0;
    cursor: pointer;
    color: #2B988F;
    align-items: center;
    flex-shrink: 0;
    line-height: 1;
}

.chat-back-btn .material-icons {
    font-size: 22px !important;
    vertical-align: middle;
}

/* ==============================
   MOBILE BOTTOM-SHEET LAYOUT
============================== */
@media (max-width: 991px) {
    #messageModal.fade .modal-dialog {
        transform: translateY(100%);
        transition: transform .35s cubic-bezier(0.32, 0.72, 0, 1) !important;
    }
    #messageModal.show .modal-dialog {
        transform: none;
    }

    #messageModal .modal-dialog {
        position: fixed !important;
        top: 80px !important;
        bottom: var(--mnav-clearance) !important;
        left: 0 !important;
        right: 0 !important;
        margin: 0 !important;
        max-width: 100% !important;
        max-height: none !important;
        min-height: 0 !important;
        width: 100% !important;
        height: auto !important;
    }

    #messageModal .modal-content {
        height: 100% !important;
        overflow: hidden !important;
        border-radius: 20px 20px 0 0 !important;
        border: none !important;
        display: flex !important;
        flex-direction: column !important;
    }

    #messageModal .album-modal-close-btn {
        display: none !important;
    }

    .mm-mobile-handle {
        display: flex !important;
    }

    #messageModal .modal-body {
        flex: 1 !important;
        min-height: 0 !important;
        overflow: hidden !important;
        padding: 0 !important;
    }

    #messageModal #messageModalBody {
        height: 100%;
        overflow: hidden;
    }

    #messageModal .chat-container {
        height: 100% !important;
        border-radius: 0 !important;
        background: #fff !important;
    }

    /* Shimmer: single column on mobile */
    #messageModal .chat-shimmer {
        height: 100% !important;
    }

    #messageModal .shimmer-sidebar {
        width: 100% !important;
        border-right: none !important;
    }

    #messageModal .shimmer-chat {
        display: none !important;
    }

    /* Default: show people-list full width, hide chat panel */
    #messageModal .people-list {
        max-width: 100% !important;
        width: 100% !important;
        flex: 1 0 100% !important;
        min-height: 0 !important;
        background: #fff !important;
        color: #111 !important;
    }

    /* Search bar on light background */
    #messageModal .search {
        border-bottom: 1px solid #f0f0f0;
    }

    #messageModal .search input {
        background: #f4f4f5 !important;
        color: #111 !important;
        border: none !important;
    }

    #messageModal .search input::placeholder {
        color: #9ca3af !important;
    }

    /* Friend items on light background */
    #messageModal .friend-item .name {
        color: #111 !important;
    }

    #messageModal .friend-item:hover:not(.active) {
        background: rgba(0,0,0,0.04) !important;
    }

    #messageModal .friend-item.active,
    #messageModal .friend-item.active:hover {
        background: rgba(43,152,143,0.08) !important;
        border-left-color: #2B988F !important;
    }

    #messageModal .friend-item.active .name {
        color: #2B988F !important;
    }

    /* Status text visible on light bg */
    #messageModal .friend-list .status.offline {
        color: #9ca3af !important;
    }

    #messageModal .friend-list .status.online {
        color: #374151 !important;
    }

    #messageModal .friend-item.non-friend .name {
        color: #6b7280 !important;
    }

    #messageModal .friend-list-divider {
        color: #d1d5db !important;
    }

    #messageModal .chat {
        display: none !important;
    }

    /* When chat-showing: swap panels */
    #messageModal .chat-container.chat-showing .people-list {
        display: none !important;
    }

    #messageModal .chat-container.chat-showing .chat {
        display: flex !important;
        flex: 1 0 100% !important;
        min-height: 0 !important;
    }

    /* Show back button when chat is active */
    .chat-container.chat-showing .chat-back-btn {
        display: inline-flex !important;
    }
}