/* CSS resets and variables */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Strict Scrollbar Hiding for all scrollable wrappers */
.chat-list,
.chat-content,
.settings-content,
.profile-content,
.app-container,
html,
body,
* {
    -ms-overflow-style: none !important;  /* IE and Edge */
    scrollbar-width: none !important;  /* Firefox */
}

.chat-list::-webkit-scrollbar,
.chat-content::-webkit-scrollbar,
.settings-content::-webkit-scrollbar,
.profile-content::-webkit-scrollbar,
.app-container::-webkit-scrollbar,
html::-webkit-scrollbar,
body::-webkit-scrollbar,
*::-webkit-scrollbar {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
    background: transparent !important;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%; /* Đổi từ 100dvh về 100% */
    overscroll-behavior-y: none;
    overflow: hidden;
    position: fixed; /* Bắt buộc để khoá cứng trang */
    top: 0;
    left: 0;
    background-color: #0b0c0e; 
}

body {
    color: #ffffff;
    font-family: 'Plus Jakarta Sans', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* App container matching the mobile aspect ratio */
.app-container {
    width: 100%;
    max-width: 480px;
    height: 100%;
    height: -webkit-fill-available;
    max-height: 960px;
    background: linear-gradient(110deg, #000000 0%, #060708 35%, #464a4f 100%);
    display: flex;
    flex-direction: column;
    padding: calc(clamp(20px, 4dvh, 40px) + env(safe-area-inset-top, 0px)) 20px calc(clamp(14px, 3dvh, 26px) + env(safe-area-inset-bottom, 0px)) 20px;
    position: relative;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

@media (max-width: 480px) {
    body {
        background-color: #000000;
    }
    .app-container {
        position: fixed;
        top: var(--visual-viewport-top, 0px);
        left: 0;
        right: 0;
        bottom: auto;
        width: 100vw;
        max-width: 100%;
        height: var(--visual-viewport-height, 100%);
        max-height: var(--visual-viewport-height, 100%) !important;
        border: none;
        box-shadow: none;
        padding: calc(clamp(16px, 3dvh, 32px) + env(safe-area-inset-top, 0px)) 16px calc(clamp(10px, 2dvh, 20px) + env(safe-area-inset-bottom, 0px)) 16px;
    }
}

/* Header Layout */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: clamp(16px, 4dvh, 32px);
    flex-shrink: 0;
}

/* Circular Back Button */
.btn-back {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: 1.2px solid rgba(255, 255, 255, 0.38);
    background: transparent;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    color: #ffffff;
}

@media (hover: hover) {
    .btn-back:hover {
        background: rgba(255, 255, 255, 0.08);
        border-color: rgba(255, 255, 255, 0.6);
        transform: scale(1.05);
    }
}

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

/* Pill profile button */
.btn-profile-pill {
    height: 52px;
    padding: 4px 6px 4px 4px;
    border-radius: 26px;
    border: 1.2px solid rgba(255, 255, 255, 0.38);
    background: rgba(255, 255, 255, 0.02);
    display: flex;
    align-items: center;
    gap: 16px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (hover: hover) {
    .btn-profile-pill:hover {
        background: rgba(255, 255, 255, 0.08);
        border-color: rgba(255, 255, 255, 0.6);
        transform: scale(1.03);
    }
}

.btn-profile-pill:active {
    transform: scale(0.97);
}

.pill-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
}

/* Circular background for arrow inside pill */
.pill-arrow-circle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    transition: all 0.2s ease;
}

@media (hover: hover) {
    .btn-profile-pill:hover .pill-arrow-circle {
        background: rgba(255, 255, 255, 0.28);
        transform: scale(1.05);
    }
}

/* Chat Content area */
.chat-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: clamp(12px, 3dvh, 22px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    margin-bottom: clamp(16px, 3dvh, 30px);
    padding-right: 4px;
    overflow-anchor: auto;
}

#chat-messages-container {
    overflow-anchor: auto;
}

/* Premium Chat Bubble Styles */
.message-bubble-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin-bottom: 12px;
    width: 100%;
    max-width: 100%;
    position: relative;
    animation: bubbleAppear 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
    overflow-anchor: auto;
}

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

.bubble-left {
    margin-right: auto;
    flex-direction: row;
}

.bubble-right {
    margin-left: auto;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid rgba(255, 255, 255, 0.2);
    flex-shrink: 0;
}

.message-bubble-content {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 18px 18px 18px 4px;
    padding: 10px 14px;
    color: #ffffff;
    font-size: 15px;
    line-height: 1.4;
    position: relative;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    transition: background-color 0.2s ease;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    max-width: 85%;
    touch-action: pan-y;
}

.bubble-right .message-bubble-content {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.2);
    border-radius: 18px 18px 4px 18px;
}

.message-bubble-content:active {
    transform: scale(0.98);
}

/* Reply Context Inside Bubble */
.message-reply-preview {
    background: rgba(255, 255, 255, 0.06);
    border-left: 3px solid rgba(255, 255, 255, 0.6);
    border-radius: 4px;
    padding: 4px 8px;
    margin-bottom: 8px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    cursor: pointer;
    max-width: 100%;
}

.reply-content-wrapper {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-grow: 1;
    min-width: 0;
}

.reply-sender {
    font-weight: 700;
    color: #ffffff;
}

.reply-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reply-media-preview {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.reply-media-preview img,
.reply-media-preview video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.reply-media-preview.file-icon {
    color: rgba(255, 255, 255, 0.6);
}

/* Text and Meta styling */
.message-text {
    word-break: break-word;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.message-inline-link {
    color: #ffffff;
    text-decoration: underline;
    word-break: break-all;
    font-weight: 500;
    transition: opacity 0.2s ease;
}

.message-inline-link:hover {
    opacity: 0.8;
}

/* Rich Link Preview Card */
.rich-link-preview-card {
    display: flex;
    flex-direction: row;
    gap: 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    padding: 10px;
    margin-top: 8px;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    max-width: 100%;
    align-items: center;
}

.rich-link-preview-card:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.15);
    transform: translateY(-1px);
}

.rich-link-preview-card:active {
    transform: translateY(0) scale(0.98);
}

.link-preview-image-wrapper {
    width: 58px;
    height: 58px;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.05);
}

.link-preview-image-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.link-preview-content {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
    min-width: 0;
}

.link-preview-domain {
    font-size: 9px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.4);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.link-preview-title {
    font-size: 13px;
    font-weight: 600;
    color: #ffffff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.link-preview-desc {
    font-size: 11px;
    line-height: 1.35;
    color: rgba(255, 255, 255, 0.55);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* Light Theme overrides */
.app-container.theme-light .message-inline-link {
    color: #0a0a0a;
}

.app-container.theme-light .rich-link-preview-card {
    background: rgba(10, 10, 10, 0.03);
    border-color: rgba(10, 10, 10, 0.06);
}

.app-container.theme-light .rich-link-preview-card:hover {
    background: rgba(10, 10, 10, 0.06);
    border-color: rgba(10, 10, 10, 0.12);
}

.app-container.theme-light .link-preview-domain {
    color: rgba(10, 10, 10, 0.45);
}

.app-container.theme-light .link-preview-title {
    color: #0a0a0a;
}

.app-container.theme-light .link-preview-desc {
    color: rgba(10, 10, 10, 0.6);
}

.app-container.theme-light .link-preview-image-wrapper {
    background: rgba(10, 10, 10, 0.04);
}

/* Neon Theme overrides */
.app-container.theme-neon .message-inline-link {
    color: #ffffff;
}

.app-container.theme-neon .rich-link-preview-card {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.12);
}

.app-container.theme-neon .rich-link-preview-card:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 4px;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.45);
    user-select: none;
}

.message-status svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

/* Sent Date divider / badge */
.message-date-badge {
    align-self: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 4px 10px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
    margin: 8px auto;
    text-align: center;
    user-select: none;
}

/* Quick hover action buttons */
.message-hover-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    background: rgba(15, 15, 15, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 20px;
    padding: 2px 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(8px);
    position: absolute;
    top: -16px;
    z-index: 10;
}

.bubble-left .message-hover-actions {
    right: -78px;
}

.bubble-right .message-hover-actions {
    left: -78px;
}

@media (hover: hover) {
    .message-bubble-wrapper:hover .message-hover-actions {
        opacity: 1;
        visibility: visible;
    }
}

.hover-action-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

@media (hover: hover) {
    .hover-action-btn:hover {
        background: rgba(255, 255, 255, 0.15);
        color: #ffffff;
    }
}

.hover-action-btn svg {
    width: 14px;
    height: 14px;
}

/* Reply bar container above bottom input bar */
.reply-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(15, 15, 15, 0.7);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 10px 14px;
    margin-bottom: 10px;
    width: 100%;
    animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.reply-bar-icon {
    color: rgba(255, 255, 255, 0.6);
    display: flex;
    align-items: center;
}

.reply-bar-icon svg {
    width: 18px;
    height: 18px;
}

.reply-bar-content {
    flex-grow: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.reply-bar-title {
    font-size: 12px;
    font-weight: 700;
    color: #ffffff;
    text-align: left;
}

.reply-bar-text {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.6);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
}

.reply-bar-media {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.reply-bar-media img,
.reply-bar-media video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.reply-bar-media svg {
    color: rgba(255, 255, 255, 0.6);
}

.reply-bar-close {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.4);
    font-size: 16px;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s;
}

@media (hover: hover) {
    .reply-bar-close:hover {
        color: #ffffff;
    }
}

/* Context Menu CSS */
.context-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.2s ease;
    display: flex;
    justify-content: center;
    align-items: center;
}

.context-menu-overlay.active {
    opacity: 1;
}

.context-menu {
    background: rgba(20, 20, 20, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 20px;
    width: 250px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    transform: scale(0.92);
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
}

.context-menu-overlay.active .context-menu {
    transform: scale(1);
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: #ffffff;
    font-size: 14px;
    font-weight: 500;
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.context-menu-item:last-child {
    border-bottom: none;
}

@media (hover: hover) {
    .context-menu-item:hover {
        background: rgba(255, 255, 255, 0.08);
    }
}

.context-menu-item.danger {
    color: #888888;
}

@media (hover: hover) {
    .context-menu-item.danger:hover {
        background: rgba(255, 59, 48, 0.15);
    }
}

.context-menu-item svg {
    width: 18px;
    height: 18px;
    color: currentColor;
}

/* Toast Notifications styling */
.toast-notification {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translate(-50%, 20px);
    background: #ffffff;
    color: #000000;
    padding: 10px 18px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
    z-index: 10000;
    pointer-events: none;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.toast-notification.active {
    transform: translate(-50%, 0);
    opacity: 1;
}

/* Bottom Input Bar */
.bottom-bar {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    position: relative;
    z-index: 999;
}

.input-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    flex-wrap: nowrap !important;
}

.input-wrapper {
    flex-grow: 1;
    position: relative;
}

.message-input {
    width: 100%;
    height: 44px;
    max-height: 120px;
    border-radius: 22px;
    border: 1.2px solid rgba(255, 255, 255, 0.38);
    background: transparent;
    padding: 11px 16px 11px 46px; /* 16px on the right since attachment is moved outside */
    color: #ffffff;
    font-family: inherit;
    font-size: 16px;
    line-height: 20px;
    outline: none;
    resize: none;
    overflow-y: auto;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

.input-action-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.55);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    transition: all 0.2s ease;
    z-index: 2;
}

@media (hover: hover) {
    .input-action-btn:hover {
        color: #ffffff;
        background: rgba(255, 255, 255, 0.1);
    }
}

.input-action-btn:active {
    transform: translateY(-50%) scale(0.92);
}

.btn-emoji {
    left: 6px;
}

.attachment-btn-container {
    position: relative;
    flex-shrink: 0;
}

.message-input::placeholder {
    color: rgba(255, 255, 255, 0.42);
}

.message-input:focus {
    border-color: rgba(255, 255, 255, 0.7);
    background: rgba(255, 255, 255, 0.02);
}

/* Plus Action Button */
.btn-plus {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1.2px solid rgba(255, 255, 255, 0.38);
    background: transparent;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    color: #ffffff;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0; /* Keep circular layout fixed */
}

@media (hover: hover) {
    .btn-plus:hover {
        background: rgba(255, 255, 255, 0.08);
        border-color: rgba(255, 255, 255, 0.6);
        transform: scale(1.05);
    }
}

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

/* Responsive adjustment for small phones under 360px width to prevent layout overflow */
@media (max-width: 360px) {
    .btn-plus {
        width: 40px !important;
        height: 40px !important;
    }
    .input-row {
        gap: 8px !important;
    }
    .message-input {
        height: 40px !important;
        font-size: 14px !important;
        padding: 9px 12px 9px 36px !important;
    }
    .btn-emoji {
        width: 32px !important;
        height: 32px !important;
    }
}

/* Keyboard open dynamic layout overrides */
.app-container.keyboard-open .header {
    margin-bottom: clamp(6px, 2dvh, 12px);
}

.app-container.keyboard-open .chat-content {
    margin-bottom: clamp(10px, 2.5dvh, 16px);
    gap: clamp(8px, 2dvh, 14px);
}

.app-container.keyboard-open .chat-view {
    padding-bottom: 6px !important;
}

/* Premium Chat Bubble Highlight & Local Context Menu */
.message-bubble-wrapper {
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), filter 0.3s ease, opacity 0.3s ease;
}

.message-bubble-wrapper.message-highlighted {
    position: relative;
    z-index: 10001 !important;
    transform: scale(1.01);
    pointer-events: auto !important;
}

.message-bubble-wrapper.message-highlighted .message-bubble-content {
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.15);
}

.chat-item.chat-item-highlighted {
    background: rgba(255, 255, 255, 0.08) !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2), inset 0 0 0 1px rgba(255, 255, 255, 0.12) !important;
    transform: scale(1.01) translateX(2px) !important;
    position: relative;
    z-index: 10001 !important;
}

.app-container.theme-light .chat-item.chat-item-highlighted {
    background: rgba(10, 10, 10, 0.07) !important;
    box-shadow: 0 6px 16px rgba(10, 10, 10, 0.05), inset 0 0 0 1px rgba(10, 10, 10, 0.08) !important;
}

.message-context-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.message-context-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.message-context-menu {
    position: fixed; /* so coordinates match getBoundingClientRect() directly */
    min-width: 185px;
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
    background: rgba(25, 25, 25, 0.85);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 14px;
    padding: 6px;
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.45);
    z-index: 10002;
    opacity: 0;
    transform: scale(0.92) translateY(-10px);
    transform-origin: top center;
    transition: opacity 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
}

.message-context-menu.active {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
}

.context-menu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 10px 14px;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.88);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

@media (hover: hover) {
    .context-menu-item:hover {
        background: rgba(255, 255, 255, 0.08);
        color: #ffffff;
    }
}

.context-menu-item:active {
    transform: scale(0.97);
}

.context-menu-item.danger {
    color: #ff453a;
}

@media (hover: hover) {
    .context-menu-item.danger:hover {
        background: rgba(255, 69, 58, 0.12);
        color: #ff453a;
    }
}

.context-menu-item svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: 0.8;
}

/* Pinned Message Banner Styles */
.pinned-message-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(20, 20, 20, 0.8);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding: 8px 16px;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.9);
    z-index: 10;
    position: relative;
    gap: 12px;
    animation: slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.pinned-message-info {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    flex: 1;
    min-width: 0;
}

.pinned-message-info svg {
    width: 14px;
    height: 14px;
    stroke: #ffffff;
    flex-shrink: 0;
}

.pinned-message-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13px;
}

.btn-unpin {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: 50%;
    transition: background 0.2s, color 0.2s;
}

@media (hover: hover) {
    .btn-unpin:hover {
        background: rgba(255, 255, 255, 0.1);
        color: #fff;
    }
}

/* Multi-select Mode Styles */
.chat-content.multi-select-active .message-bubble-wrapper {
    cursor: pointer;
    user-select: none;
}

.message-checkbox-container {
    display: none;
    align-items: center;
    justify-content: center;
    margin-right: 10px;
    flex-shrink: 0;
    animation: fadeIn 0.2s ease;
}

.chat-content.multi-select-active .message-checkbox-container {
    display: flex;
}

.message-checkbox {
    width: 18px;
    height: 18px;
    border-radius: 6px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, border-color 0.2s;
}

.message-bubble-wrapper.selected .message-checkbox {
    background-color: #ffffff;
    border-color: #ffffff;
}

.message-checkbox svg {
    width: 12px;
    height: 12px;
    stroke: #000;
    stroke-width: 3.5;
    display: none;
}

.message-bubble-wrapper.selected .message-checkbox svg {
    display: block;
}

.multi-select-action-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(60px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: rgba(20, 20, 20, 0.9);
    backdrop-filter: blur(24px);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-left: 20px;
    padding-right: 20px;
    z-index: 1000;
    transform: translateY(110%);
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s, visibility 0.3s;
}

.multi-select-action-bar.active {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
    visibility: visible;
}

.multi-select-count {
    font-size: 14px;
    color: #fff;
    font-weight: 500;
}

.multi-select-actions {
    display: flex;
    gap: 12px;
}

.btn-multi-action {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #fff;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s, transform 0.1s;
}

@media (hover: hover) {
    .btn-multi-action:hover {
        background: rgba(255, 255, 255, 0.15);
    }
}

.btn-multi-action:active {
    transform: scale(0.97);
}

.btn-multi-action.danger {
    background: rgba(255, 69, 58, 0.15);
    border-color: rgba(255, 69, 58, 0.2);
    color: #ff453a;
}

@media (hover: hover) {
    .btn-multi-action.danger:hover {
        background: rgba(255, 69, 58, 0.25);
    }
}

@keyframes slideDown {
    from { transform: translateY(-100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

/* Hide bottom bar and reply bar during multi-select to avoid overlap/stacking */
.chat-view.multi-select-active .bottom-bar,
.chat-view.multi-select-active .reply-bar {
    display: none !important;
}

/* Adjust scroll container padding to prevent content overlap with multi-select bar */
.chat-view.multi-select-active #chat-messages-container {
    padding-bottom: 80px !important;
}

/* ==========================================================================
   Responsive & Multi-device UI Optimizations (Mobile, Tablet, Desktop)
   ========================================================================== */

/* 1. Extremely Small Screens (compact mobile devices, Galaxy Fold cover, etc.) */
@media (max-width: 350px) {
    .app-container {
        padding: calc(12px + env(safe-area-inset-top, 0px)) 10px calc(16px + env(safe-area-inset-bottom, 0px)) 10px !important;
    }

    .chat-view {
        padding: calc(12px + env(safe-area-inset-top, 0px)) 10px calc(10px + env(safe-area-inset-bottom, 0px)) 10px !important;
    }

    .header {
        margin-bottom: 16px !important;
    }

    .logo-text {
        font-size: 20px !important;
    }

    .chat-list {
        gap: 16px !important;
    }

    .chat-item {
        gap: 10px !important;
        padding: 6px 4px !important;
        margin: 0 -4px !important;
    }

    .chat-avatar {
        width: 50px !important;
        height: 50px !important;
    }

    .chat-name {
        font-size: 16px !important;
    }

    .chat-last-msg {
        font-size: 12px !important;
    }

    .btn-search, .btn-settings, .btn-profile-pill {
        width: 36px !important;
        height: 36px !important;
    }

    .btn-profile-pill {
        padding: 2px 10px 2px 2px !important;
        gap: 6px !important;
    }

    .pill-avatar {
        width: 30px !important;
        height: 30px !important;
    }

    .pill-arrow {
        display: none !important;
    }

    .message-input {
        padding: 11px 36px !important;
        font-size: 14px !important;
    }

    .btn-plus {
        width: 40px !important;
        height: 40px !important;
    }

    .btn-back {
        width: 40px !important;
        height: 40px !important;
    }

    .chat-view .btn-profile-pill {
        height: 40px !important;
        gap: 10px !important;
    }

    .chat-view .pill-avatar {
        width: 32px !important;
        height: 32px !important;
    }

    .chat-view .pill-arrow-circle {
        width: 28px !important;
        height: 28px !important;
    }

    .chat-view .pill-name {
        max-width: 70px !important;
    }

    #chat-view-status {
        max-width: 70px !important;
    }
}

/* 2. Tablets and Desktops Dual-pane Layout */
@media (min-width: 768px) {
    body {
        background-color: #0b0c0e;
    }

    .app-container {
        width: 100vw !important;
        max-width: 100% !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-height: 100% !important;
        border-radius: 0 !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        display: flex !important;
        flex-direction: row !important;
        overflow: hidden !important;
    }

    /* Left pane style (Main list) */
    .main-view {
        width: 360px !important;
        flex-shrink: 0 !important;
        height: 100% !important;
        border-right: 1px solid rgba(255, 255, 255, 0.08) !important;
        padding: 24px 20px !important;
        background: rgba(10, 11, 13, 0.6) !important;
        backdrop-filter: blur(20px) !important;
        transform: none !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        transition: none !important;
    }

    /* Right pane views (Chat, Settings, Profile) */
    .chat-view {
        left: 360px !important;
        width: calc(100% - 360px) !important;
        height: 100% !important;
        transform: translateX(30px) !important;
        opacity: 0 !important;
        pointer-events: none !important;
        visibility: hidden !important;
        transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.28s ease, visibility 0.28s ease !important;
        padding: 24px 30px !important;
        background: rgba(6, 7, 8, 0.2) !important;
        border-left: none !important;
        z-index: 10 !important;
    }

    .chat-view.active {
        transform: translateX(0) !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        visibility: visible !important;
    }

    /* Hide Back button in Chat Thread on desktop */
    .chat-view:not(.settings-view):not(.profile-view) .btn-back {
        display: none !important;
    }

    /* Keep Back/Close buttons inside Settings and Profile views on desktop */
    .settings-view .btn-back,
    .profile-view .btn-back {
        display: flex !important;
    }

    /* Limit Chat Bubble width on wider screens */
    .message-bubble-content {
        max-width: 70% !important;
    }
}

/* Real-time Message Reactions & Seen Indicators styling */
.message-reaction-bar {
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 6px 10px;
    gap: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 4px;
}
.reaction-btn {
    font-size: 20px;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: transform 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    padding: 4px;
    border-radius: 8px;
}
@media (hover: hover) {
    .reaction-btn:hover {
        transform: scale(1.3);
        background: rgba(255, 255, 255, 0.08);
    }
}
.reaction-btn:active {
    transform: scale(0.9);
}
.message-reaction-badge {
    position: absolute;
    bottom: -10px;
    right: 10px;
    background: rgba(30, 30, 30, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 2px 6px;
    font-size: 11px;
    display: flex;
    align-items: center;
    gap: 3px;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.4);
    z-index: 5;
    user-select: none;
    transition: transform 0.15s, background-color 0.15s;
}
@media (hover: hover) {
    .message-reaction-badge:hover {
        transform: scale(1.08);
        background: rgba(45, 45, 45, 0.95);
    }
}
.bubble-left .message-reaction-badge {
    right: auto;
    left: 10px;
}
.typing-indicator-dots {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    margin-left: 4px;
}
.typing-indicator-dots span {
    width: 4px;
    height: 4px;
    background-color: currentColor;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite both;
    opacity: 0.6;
}
.typing-indicator-dots span:nth-child(2) {
    animation-delay: 0.2s;
}
.typing-indicator-dots span:nth-child(3) {
    animation-delay: 0.4s;
}
@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Calling Overlay Styling */
.calling-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 12, 16, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    animation: fadeInCall 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.calling-content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: 60px 24px;
    position: relative;
}

/* User Info Layout */
.call-user-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    margin-top: 40px;
    z-index: 2;
    transition: all 0.3s ease;
}

.call-avatar-container {
    position: relative;
    width: 120px;
    height: 120px;
    margin-bottom: 8px;
}

.call-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.2);
    position: relative;
    z-index: 2;
}

.pulse-ring {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid #ffffff;
    animation: pulseRing 2s infinite;
    z-index: 1;
}

.call-username {
    font-size: 24px;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: -0.5px;
}

.call-status {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.6);
    letter-spacing: 0.5px;
}

.call-timer {
    font-size: 18px;
    font-weight: 600;
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
    padding: 4px 12px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    margin-top: 8px;
    animation: fadeInCall 0.3s ease;
}

/* Control Buttons styling */
.call-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    width: 100%;
    z-index: 2;
}

.call-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    color: #ffffff;
}

@media (hover: hover) {
    .call-btn:hover {
        transform: scale(1.08);
    }
}

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

.btn-mute, .btn-camera {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.btn-mute.active, .btn-camera.active {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.4);
}

.btn-mute.disabled, .btn-camera.disabled {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    color: #888888;
}

.btn-hangup {
    background: #222222; border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
}

@media (hover: hover) {
    .btn-hangup:hover {
        background: #333333;
        box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
    }
}

.btn-accept {
    background: #ffffff; color: #000000;
    box-shadow: 0 4px 15px rgba(255, 255, 255, 0.4);
}

@media (hover: hover) {
    .btn-accept:hover {
        background: #e5e5e5; color: #000000;
        box-shadow: 0 6px 20px rgba(255, 255, 255, 0.6);
    }
}

/* Video Container Layout */
.call-video-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    background: #000000;
    display: none;
    overflow: hidden;
}

.remote-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000000;
}

.local-video {
    position: absolute;
    top: 24px;
    right: 24px;
    width: 90px;
    height: 130px;
    border-radius: 16px;
    object-fit: cover;
    border: 1.5px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    background: #111111;
    z-index: 10;
}

/* Keyframes */
@keyframes pulseRing {
    0% { transform: scale(0.95); opacity: 1; }
    50% { transform: scale(1.15); opacity: 0.5; }
    100% { transform: scale(1.3); opacity: 0; }
}

@keyframes fadeInCall {
    from { opacity: 0; transform: scale(1.05); }
    to { opacity: 1; transform: scale(1); }
}

/* Upgraded Message Attachments & Lightbox Styling */
.message-attachment-image-container,
.message-attachment-video-container {
    position: relative;
    margin-bottom: 6px;
    border-radius: 16px;
    overflow: hidden;
    max-width: 280px;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.08);
    transition: transform 0.2s ease, border-color 0.2s ease;
}

@media (hover: hover) {
    .message-attachment-image-container:hover,
    .message-attachment-video-container:hover {
        transform: scale(1.015);
        border-color: rgba(255, 255, 255, 0.2);
    }
}

.message-attachment-image-container img {
    width: 100%;
    height: auto;
    display: block;
    max-height: 220px;
    object-fit: cover;
}

.message-attachment-video-container video {
    width: 100%;
    height: auto;
    display: block;
    max-height: 220px;
    object-fit: cover;
    background: #000;
}

/* Floating Glass download button on hover */
.media-download-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(15, 15, 20, 0.75);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #ffffff;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transform: scale(0.85);
    transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), background 0.2s ease;
    z-index: 10;
}

@media (hover: hover) {
    .message-attachment-image-container:hover .media-download-btn,
    .message-attachment-video-container:hover .media-download-btn {
        opacity: 1;
        transform: scale(1);
    }
}

@media (hover: hover) {
    .media-download-btn:hover {
        background: rgba(15, 15, 20, 0.95);
        border-color: rgba(255, 255, 255, 0.3);
        color: #ffffff;
    }
}

/* Fullscreen Media Lightbox Viewer */
.media-lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(6, 7, 10, 0.88);
    backdrop-filter: blur(40px) saturate(210%);
    -webkit-backdrop-filter: blur(40px) saturate(210%);
    z-index: 35000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1), backdrop-filter 0.35s ease;
}

.media-lightbox-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.lightbox-header {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    height: 64px;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(24px) saturate(160%);
    -webkit-backdrop-filter: blur(24px) saturate(160%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 32px;
    z-index: 35002;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.lightbox-title {
    color: #ffffff;
    font-size: 14.5px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: calc(100% - 140px);
    letter-spacing: -0.2px;
    font-family: 'Plus Jakarta Sans', sans-serif;
    opacity: 0.9;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.lightbox-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.lightbox-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.85);
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

@media (hover: hover) {
    .lightbox-btn:hover {
        background: rgba(255, 255, 255, 0.12);
        border-color: rgba(255, 255, 255, 0.2);
        color: #ffffff;
        transform: scale(1.08);
        box-shadow: 0 0 15px rgba(255, 255, 255, 0.25);
    }
}

.lightbox-btn:active {
    transform: scale(0.92);
}

.lightbox-content-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 100px 32px 60px 32px;
    box-sizing: border-box;
}

.lightbox-media {
    max-width: 92%;
    max-height: 84%;
    object-fit: contain;
    border-radius: 16px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7), 0 0 1px rgba(255, 255, 255, 0.15);
    transform: scale(0.96);
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.35s ease;
}

.media-lightbox-overlay.active .lightbox-media {
    transform: scale(1);
}

.lightbox-media-video {
    outline: none;
    background: #000;
}

/* Immersive Mode */
.media-lightbox-overlay {
    user-select: none;
    -webkit-user-select: none;
}
.media-lightbox-overlay.immersive {
    background: rgba(0, 0, 0, 1);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}
.media-lightbox-overlay.immersive .lightbox-header,
.media-lightbox-overlay.immersive .lightbox-arrow-btn,
.media-lightbox-overlay.immersive .lightbox-counter {
    opacity: 0 !important;
    pointer-events: none !important;
    transform: translateY(-10px);
}
.lightbox-header, .lightbox-arrow-btn, .lightbox-counter {
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* File Card for Generic Documents */
.lightbox-file-card {
    background: rgba(25, 25, 30, 0.85);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 28px;
    padding: 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    max-width: 320px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
    opacity: 0;
    transform: scale(0.95);
    animation: fileCardIn 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
@keyframes fileCardIn {
    to { opacity: 1; transform: scale(1); }
}
.lightbox-file-card-icon {
    width: 72px;
    height: 72px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}
.lightbox-file-card-name {
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    word-break: break-all;
    font-family: 'Plus Jakarta Sans', sans-serif;
    line-height: 1.4;
}
.lightbox-file-card-ext {
    color: rgba(255,255,255,0.5);
    font-size: 13px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.lightbox-file-card-btn {
    background: #fff;
    color: #000;
    border: none;
    padding: 14px 28px;
    border-radius: 100px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
@media (hover: hover) {
    .lightbox-file-card-btn:hover {
        background: #f0f0f0;
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    }
}
.lightbox-file-card-btn:active {
    transform: scale(0.94) translateY(0);
    background: #e0e0e0;
}
.lightbox-media.dragging {
    transition: none !important;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ==========================================================================
   Upgraded Attachments Menu & Previews Queue Styles
   ========================================================================== */
.attachment-btn-container {
    position: relative;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
}

.attachment-btn-container .btn-attachment {
    margin: 0;
}

.attachment-menu {
    position: absolute;
    bottom: 54px;
    right: 0;
    background: rgba(18, 18, 22, 0.95);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    padding: 6px;
    display: none;
    flex-direction: column;
    gap: 4px;
    z-index: 1200;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    min-width: 160px;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.22s cubic-bezier(0.16, 1, 0.3, 1), transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.attachment-menu.active {
    display: flex;
    opacity: 1;
    transform: translateY(0);
}

.attachment-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.85);
    font-size: 13.5px;
    font-weight: 500;
    padding: 9px 12px;
    border-radius: 9px;
    cursor: pointer;
    text-align: left;
    transition: background 0.2s, color 0.2s;
    font-family: inherit;
    width: 100%;
}

.attachment-menu-item:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #ffffff;
}

.attachment-menu-item svg {
    color: rgba(255, 255, 255, 0.5);
    transition: color 0.2s;
}

.attachment-menu-item:hover svg {
    color: #ffffff;
}

/* Previews Container */
.attachment-preview-container {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    overflow-x: auto;
    width: 100%;
    box-sizing: border-box;
    max-height: 106px;
    border-radius: 16px 16px 0 0;
}

/* Custom Scrollbar for Previews */
.attachment-preview-container::-webkit-scrollbar {
    height: 4px;
}
.attachment-preview-container::-webkit-scrollbar-track {
    background: transparent;
}
.attachment-preview-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 2px;
}

.attachment-preview-item {
    position: relative;
    width: 68px;
    height: 68px;
    border-radius: 10px;
    overflow: hidden;
    flex-shrink: 0;
    border: 1.2px solid rgba(255, 255, 255, 0.08);
    background: rgba(10, 10, 12, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
}

.attachment-preview-item img,
.attachment-preview-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.attachment-preview-file-icon {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4px;
    text-align: center;
    width: 100%;
    height: 100%;
}

.attachment-preview-file-icon svg {
    color: #ffffff;
    margin-bottom: 4px;
}

.attachment-preview-file-name {
    font-size: 9px;
    color: rgba(255, 255, 255, 0.65);
    max-width: 60px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

.attachment-preview-delete {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(0, 0, 0, 0.75);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: background 0.2s, transform 0.15s;
    line-height: 1;
}

.attachment-preview-delete:hover {
    background: #ff3b30;
    border-color: #888888;
    transform: scale(1.05);
}

.attachment-preview-add-more {
    width: 66px;
    height: 66px;
    border: 1.5px dashed rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    background: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.45);
    flex-shrink: 0;
    gap: 4px;
    transition: all 0.22s ease;
}

.attachment-preview-add-more:hover {
    border-color: #ffffff;
    color: #ffffff;
    background: rgba(255, 255, 255, 0.03);
}

.attachment-preview-add-more span {
    font-size: 10px;
    font-weight: 600;
}

/* Telegram-style Inline Upload progress on message bubble */
.message-bubble-wrapper.message-uploading .media-grid-item img,
.message-bubble-wrapper.message-uploading .media-grid-item video {
    filter: blur(10px) brightness(0.5);
    transition: filter 0.3s ease;
}

.message-bubble-wrapper.message-uploading .message-attachment-file-box {
    opacity: 0.65;
    background: rgba(255, 255, 255, 0.03) !important;
    border-color: rgba(255, 255, 255, 0.05) !important;
    pointer-events: none;
}

.bubble-uploading-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.4);
    z-index: 100;
    gap: 12px;
    border-radius: inherit;
    padding: 12px;
    box-sizing: border-box;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.bubble-uploading-circle-wrapper {
    position: relative;
    width: 46px;
    height: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bubble-uploading-circle-svg {
    width: 46px;
    height: 46px;
    transform: rotate(-90deg);
}

.bubble-uploading-circle-svg .circle-bg {
    stroke: rgba(255, 255, 255, 0.12);
}

.bubble-uploading-circle-svg .circle-progress {
    stroke: #ffffff;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.1s ease-out;
}

.bubble-uploading-cancel-btn {
    position: absolute;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 0;
}

.bubble-uploading-cancel-btn:hover {
    background: rgba(255, 59, 48, 0.25);
    color: #888888;
    transform: scale(1.08);
}

.bubble-uploading-cancel-btn:active {
    transform: scale(0.92);
}

.bubble-uploading-cancel-btn svg {
    width: 11px;
    height: 11px;
    display: block;
}

.bubble-uploading-status-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    width: 90%;
    max-width: 180px;
}

.bubble-uploading-status-text {
    font-size: 11px;
    font-weight: 700;
    color: #ffffff;
    text-shadow: 0 1px 3px rgba(0,0,0,0.85);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: 'Plus Jakarta Sans', sans-serif;
    letter-spacing: -0.1px;
}

.bubble-uploading-bytes-text {
    font-size: 9.5px;
    color: #ffffff;
    font-family: 'Courier New', Courier, monospace;
    font-weight: 700;
    text-shadow: 0 1px 3px rgba(0,0,0,0.85);
    white-space: nowrap;
    letter-spacing: -0.2px;
}

.bubble-uploading-progress-track {
    width: 100%;
    height: 3px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 1.5px;
    overflow: hidden;
    margin-top: 2px;
}

.bubble-uploading-progress-bar {
    height: 100%;
    background: #ffffff;
    width: 0%;
    border-radius: 1.5px;
    transition: width 0.1s ease-out;
}

/* Full-screen upload overlay removed in favor of inline bubble upload progress */

/* ==========================================================================
   Grouped Media Collage Grids & Caption Styles
   ========================================================================== */
.message-media-grid {
    display: grid;
    gap: 4px;
    border-radius: 12px;
    overflow: hidden;
    width: 280px !important;
    margin-bottom: 4px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.message-media-grid.media-grid-1 {
    grid-template-columns: 1fr;
    aspect-ratio: 4 / 3;
}
.message-media-grid.media-grid-2 {
    grid-template-columns: 1fr 1fr;
    aspect-ratio: 3 / 2;
}
.message-media-grid.media-grid-3 {
    grid-template-columns: 1.5fr 1fr;
    grid-template-rows: 1fr 1fr;
    aspect-ratio: 4 / 3;
}
.message-media-grid.media-grid-3 .media-grid-item:nth-child(1) {
    grid-row: span 2;
}
.message-media-grid.media-grid-4 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    aspect-ratio: 1 / 1;
}

.media-grid-item {
    position: relative;
    width: 100%;
    height: 100%;
    cursor: pointer;
    background: #090a0c;
    overflow: hidden;
}

/* Shimmer placeholder background */
.media-grid-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.03) 25%, rgba(255, 255, 255, 0.07) 50%, rgba(255, 255, 255, 0.03) 75%);
    background-size: 200% 100%;
    animation: media-shimmer 1.5s infinite;
    z-index: 1;
}

@keyframes media-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Spinner inside media items */
.media-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    z-index: 2;
    pointer-events: none;
}

.media-spinner-circle {
    width: 100%;
    height: 100%;
    border: 2px solid rgba(255, 255, 255, 0.07);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.media-grid-item img,
.media-grid-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    opacity: 0;
    transition: transform 0.25s ease, opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    z-index: 3;
}

/* Fade in loaded media */
.media-grid-item img.loaded,
.media-grid-item video.loaded {
    opacity: 1;
}

/* Hover effects */
.media-grid-item:hover img.loaded,
.media-grid-item:hover video.loaded {
    transform: scale(1.03);
}

/* Hide shimmer & spinner when loaded or errored */
.media-grid-item:has(img.loaded)::before,
.media-grid-item:has(video.loaded)::before,
.media-grid-item:has(.media-error-placeholder)::before {
    display: none;
}
.media-grid-item:has(img.loaded) .media-spinner,
.media-grid-item:has(video.loaded) .media-spinner {
    display: none;
}

/* Error Placeholder */
.media-error-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #111215;
    color: rgba(255, 255, 255, 0.4);
    font-size: 11px;
    font-weight: 500;
    gap: 6px;
    z-index: 4;
    user-select: none;
    border: 1px dashed rgba(255, 255, 255, 0.08);
    box-sizing: border-box;
}

.media-error-placeholder svg {
    stroke: rgba(255, 255, 255, 0.25);
    width: 20px;
    height: 20px;
}

.media-grid-more-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 20px;
    font-weight: 700;
    z-index: 5;
    user-select: none;
}

.video-play-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.2);
    pointer-events: none;
}

.video-play-overlay svg {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    color: #fff;
    padding: 8px;
    box-shadow: 0 4px 12px rgba(255, 255, 255, 0.35);
}

.message-caption {
    margin-bottom: 6px;
    font-size: 15px;
    line-height: 1.45;
    color: #ffffff;
    word-break: break-word;
}

.message-files-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    max-width: 290px;
    margin-top: 4px;
}

/* ==========================================================================
   Upgraded Lightbox Gallery Navigation Styles
   ========================================================================== */
.lightbox-arrow-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.85);
    border-radius: 50%;
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 35003;
    transition: all 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    outline: none;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.lightbox-arrow-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-50%) scale(1.1);
    color: #ffffff;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5), 0 0 20px rgba(255, 255, 255, 0.2);
}

.lightbox-arrow-btn:active {
    transform: translateY(-50%) scale(0.92);
}

.lightbox-arrow-btn.prev {
    left: 32px;
}

.lightbox-arrow-btn.next {
    right: 32px;
}

.lightbox-counter {
    position: absolute;
    bottom: 32px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 13px;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(24px) saturate(160%);
    -webkit-backdrop-filter: blur(24px) saturate(160%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 8px 18px;
    border-radius: 20px;
    z-index: 35003;
    letter-spacing: 0.5px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.lightbox-media {
    transition: transform 0.24s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.24s ease;
}

/* Hide navigation arrow buttons on mobile screen */
@media (max-width: 768px) {
    .lightbox-arrow-btn {
        display: none !important;
    }
}

/* ── Swipe to Reply & Double Tap Heart Animation ── */
.swipe-reply-indicator {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: scale(0.7) translateY(-50%);
    transform-origin: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.25);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    color: #ffffff;
    transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
    z-index: 10;
}
.swipe-reply-indicator svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
}
.swipe-reply-indicator.active {
    background: #10b981;
    border-color: #10b981;
    color: #ffffff;
    box-shadow: 0 0 16px rgba(16, 185, 129, 0.5);
    transform: scale(1.15) translateY(-50%);
}

.floating-heart-tap {
    position: fixed;
    pointer-events: none;
    z-index: 99999;
    font-size: 36px;
    animation: floatHeart 0.8s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
    filter: drop-shadow(0 4px 10px rgba(0,0,0,0.3));
}

@keyframes floatHeart {
    0% {
        transform: translate(-50%, -50%) scale(0.3);
        opacity: 0;
    }
    15% {
        transform: translate(-50%, -50%) scale(1.3);
        opacity: 1;
    }
    30% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -80px) scale(0.6) rotate(-15deg);
        opacity: 0;
    }
}

.heart-double-tap-anim {
    animation: heartDoubleTapScale 0.38s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes heartDoubleTapScale {
    0% { transform: scale(1); }
    50% { transform: scale(0.94); }
    100% { transform: scale(1); }
}

/* Chat view Header Premium Refinements */
/* Consistent sizing for back and call buttons in chat view on desktop */
.chat-header {
    gap: 12px !important;
}

.chat-header .btn-back {
    width: 46px;
    height: 46px;
    border: 1px solid rgba(255, 255, 255, 0.3) !important; /* Faint border made clearer */
    background: rgba(255, 255, 255, 0.03);
    flex-shrink: 0;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-header .btn-back svg {
    width: 22px;
    height: 22px;
}

/* Chat view profile pill: remove search, left-align beautifully */
.chat-header .btn-profile-pill {
    height: 46px;
    padding: 3px 16px 3px 3px !important; /* Left-aligned padding */
    border-radius: 23px !important;
    border: 1px solid rgba(255, 255, 255, 0.3) !important; /* Faint border made clearer */
    background: rgba(255, 255, 255, 0.03) !important;
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 12px !important;
}

/* Chat view avatar size */
.chat-header .pill-avatar {
    width: 38px !important;
    height: 38px !important;
    flex-shrink: 0;
}

/* Allow longer names and statuses to display without truncation now that search is removed */
.chat-header .pill-name {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.2;
    color: #ffffff;
    max-width: 200px !important; /* Expanded from 120px */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header #chat-view-status {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
    max-width: 200px !important; /* Expanded from 120px */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Mobile responsive alignment (max-width: 480px) */
@media (max-width: 480px) {
    .chat-header {
        gap: 8px !important;
    }

    .chat-header .btn-back {
        width: 40px !important;
        height: 40px !important;
        border: 1px solid rgba(255, 255, 255, 0.3) !important;
    }
    
    .chat-header .btn-back svg {
        width: 18px !important;
        height: 18px !important;
    }

    .chat-header .btn-profile-pill {
        height: 40px !important;
        padding: 3px 12px 3px 3px !important; /* Left-aligned padding on mobile */
        border-radius: 20px !important;
        border: 1px solid rgba(255, 255, 255, 0.3) !important;
        gap: 10px !important;
    }

    .chat-header .pill-avatar {
        width: 32px !important;
        height: 32px !important;
    }

    .chat-header .pill-name {
        max-width: 130px !important; /* Expanded from 70px since search button is removed */
    }

    .chat-header #chat-view-status {
        max-width: 130px !important; /* Expanded from 70px since search button is removed */
    }
}

/* Floating Scroll to Bottom Button (Telegram-style) */
.btn-scroll-bottom {
    position: absolute;
    right: 20px;
    bottom: 84px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(30, 32, 38, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.16);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8) translateY(10px);
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 90;
}

.btn-scroll-bottom.visible {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1) translateY(0);
}

.btn-scroll-bottom:hover {
    background: rgba(45, 48, 58, 0.95);
    border-color: rgba(255, 255, 255, 0.3);
    transform: scale(1.08) translateY(0);
}

.btn-scroll-bottom:active {
    transform: scale(0.95) translateY(0);
}

.scroll-bottom-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: #10b981;
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.5);
    animation: badgePop 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes badgePop {
    0% { transform: scale(0); }
    100% { transform: scale(1); }
}


