/* ============================================
   CHAT PANEL - BEM NAMING CONVENTION
   ============================================ */

/* Body scroll lock when chat panel is open */
body.chatPanelOpen,
html.chatPanelOpen {
    overflow: hidden !important;
}

/* ============================================
   OVERLAY
   ============================================ */
.chatPanelOverlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: -1;
    display: none;
    transform: translateX(100%);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

    .chatPanelOverlay.active {
        z-index: 9998;
        display: flex;
        transform: translateX(0);
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

/* ============================================
   SIDE PANEL CONTAINER
   ============================================ */
.chatPanelSidePanel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 450px;
    max-width: 90vw;
    background: #F7F8FA;
    z-index: -1;
    display: none;
    flex-direction: column;
    transform: translateX(100%);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

    .chatPanelSidePanel.active {
        z-index: 10001;
        display: flex;
        transform: translateX(0);
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        transition: transform 0.3s ease, opacity 0.3s ease;
    }

/* Mobile: Full-screen overlay */
@media (max-width: 768px) {
    .chatPanelSidePanel {
        width: 100vw;
        max-width: 100vw;
    }
}

/* ============================================
   PANEL HEADER
   ============================================ */
.chatPanelHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1.25rem;
    background: linear-gradient(135deg, #1775FF 0%, #0056D2 100%);
    color: white;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.chatPanelTitle {
    font-size: 2rem;
    font-weight: 700;
    margin: 0;
    color: white;
}

.chatPanelClose {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 2.25rem;
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.chatPanelClose:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

/* ============================================
   CONTENT AREA
   ============================================ */
.chatPanelContentArea {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.chatPanelView {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.chatPanelViewHidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* ============================================
   CONVERSATIONS LIST
   ============================================ */
.chatConversationsList {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Search Container */
.chatSearchContainer {
    padding: 1rem;
    background: white;
    border-bottom: 1px solid #E5E7EB;
}

.chatSearchInputWrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.chatSearchIcon {
    position: absolute;
    left: 1rem;
    color: #9CA3AF;
    font-size: 1.45rem;
    margin-bottom: 0.2rem;
}

.chatSearchInput {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 3.25rem;
    border: 1px solid #E5E7EB;
    border-radius: 8px;
    font-size: 1.5rem;
    outline: none;
    transition: all 0.2s ease;
}

.chatSearchInput:focus {
    border-color: #1775FF;
    box-shadow: 0 0 0 3px rgba(23, 117, 255, 0.1);
}

/* Conversations Container */
.chatConversationsContainer {
    flex: 1;
    overflow-y: auto;
    background: #F7F8FA;
}

.chatConversationItems {
    padding: 0.5rem;
}

/* Loading State */
.chatLoadingState {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 2rem;
}

.chatLoadingSpinner {
    font-size: 3rem;
    color: #1775FF;
    margin-bottom: 1rem;
}

.chatLoadingText {
    color: #6B7280;
    font-size: 1.25rem;
}

/* Empty State */
.chatEmptyState {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 2rem;
    text-align: center;
}

.chatEmptyIcon {
    font-size: 4rem;
    color: #D1D5DB;
    margin-bottom: 1rem;
}

.chatEmptyTitle {
    font-size: 1.75rem;
    font-weight: 600;
    color: #374151;
    margin: 0 0 0.5rem 0;
}

.chatEmptyText {
    color: #6B7280;
    font-size: 1.4rem;
    margin: 0;
    max-width: 300px;
}

/* ============================================
   CONVERSATION CARD
   ============================================ */
.chatConversationCard {
    display: flex;
    align-items: center;
    padding: 1rem;
    background: white;
    border-radius: 12px;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    gap: 1rem;
}

.chatConversationCard:hover {
    background: #F9FAFB;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    transform: translateX(-2px);
}

.chatConversationCard:active {
    transform: scale(0.98);
}

.chatConversationAvatar {
    flex-shrink: 0;
}

.chatConversationAvatarImg {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #E5E7EB;
}

.chatConversationContent {
    flex: 1;
    min-width: 0;
}

.chatConversationHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.25rem;
    gap: 1rem;
}

.chatConversationName {
    font-size: 1.4rem;
    font-weight: 600;
    color: #111827;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left;
}

.chatConversationTime {
    font-size: 1.3rem;
    color: #9CA3AF;
    flex-shrink: 0;
}

.chatConversationFooter {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.chatConversationMessage {
    font-size: 1.4rem;
    color: #6B7280;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    text-align: left;
}

.chatConversationBadge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    background: #1775FF;
    color: white;
    border-radius: 12px;
    font-size: 1.3rem;
    font-weight: 700;
    flex-shrink: 0;
}

/* ============================================
   MESSAGES VIEW
   ============================================ */
.chatMessagesView {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: white;
}

/* Messages Header */
.chatMessagesHeader {
    display: flex;
    align-items: center;
    padding: 1rem 1.5rem;
    background: white;
    border-bottom: 1px solid #E5E7EB;
    flex-shrink: 0;
}

.chatBackButton {
    background: none;
    border: none;
    color: #1775FF;
    font-size: 2rem;
    cursor: pointer;
    padding: 0.5rem;
    margin-right: 0.75rem;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.chatBackButton:hover {
    background: #F3F4F6;
}

.chatMessagesHeaderUser {
    display: flex;
    align-items: center;
    flex: 1;
}

.chatMessagesHeaderAvatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #E5E7EB;
    margin-right: 0.75rem;
}

.chatMessagesHeaderInfo {
    flex: 1;
    min-width: 0;
}

.chatMessagesHeaderName {
    font-size: 1.75rem;
    font-weight: 600;
    color: #111827;
    margin: 0 0 0.125rem 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left;
}

.chatMessagesHeaderStatus {
    font-size: 0.75rem;
    color: #9CA3AF;
}

/* Messages Container */
.chatMessagesContainer {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 1rem;
    background: #F9FAFB;
    position: relative;
}

.chatMessagesLoadingState {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.chatMessagesList {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* ============================================
   MESSAGE BUBBLE
   ============================================ */
.chatMessageBubble {
    display: flex;
    flex-direction: column;
    max-width: 70%;
    animation: chatMessageSlideIn 0.2s ease;
}

@keyframes chatMessageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Sent messages (right-aligned, blue) */
.chatMessageBubble.chatMessageSent {
    align-self: flex-end;
}

.chatMessageBubble.chatMessageSent .chatMessageContent {
    background: linear-gradient(135deg, #1775FF 0%, #0056D2 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.chatMessageBubble.chatMessageSent .chatMessageMeta {
    align-self: flex-end;
}

.chatMessageBubble.chatMessageSent .chatMessageStatus {
    color: #1775FF;
}

/* Received messages (left-aligned, gray) */
.chatMessageBubble.chatMessageReceived {
    align-self: flex-start;
}

.chatMessageBubble.chatMessageReceived .chatMessageContent {
    background: #E5E7EB;
    color: #111827;
    border-bottom-left-radius: 4px;
}

.chatMessageBubble.chatMessageReceived .chatMessageMeta {
    align-self: flex-start;
}

/* Message Content */
.chatMessageContent {
    padding: 0.75rem 1rem;
    border-radius: 12px;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.chatMessageText {
    font-size: 1.4rem;
    margin: 0;
    line-height: 1.5;
    white-space: pre-wrap;
}

/* Message Meta */
.chatMessageMeta {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem 0;
}

.chatMessageTime {
    font-size: 1.2rem;
    color: #9CA3AF;
}

.chatMessageStatus {
    font-size: 1.4rem;
    color: #10B981;
    font-weight: 900;
    padding-left: 0.25rem;
}

/* Deleted message style */
.chatMessageBubble.chatMessageDeleted .chatMessageContent {
    background: #FEF2F2;
    color: #B91C1C;
    font-style: italic;
}

/* Date Separator */
.chatDateSeparator {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0.2rem 0;
}

.chatDateSeparatorText {
    font-size: 1.4rem;
    color: #9CA3AF;
    background: white;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-weight: 500;
}

/* Typing Indicator */
.chatTypingIndicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: #E5E7EB;
    border-radius: 12px;
    max-width: 70px;
    margin-top: 0.5rem;
}

.chatTypingDots {
    display: flex;
    gap: 3px;
}

.chatTypingDots span {
    width: 6px;
    height: 6px;
    background: #6B7280;
    border-radius: 50%;
    animation: chatTypingBounce 1.4s infinite ease-in-out;
}

.chatTypingDots span:nth-child(1) {
    animation-delay: -0.32s;
}

.chatTypingDots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes chatTypingBounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

/* ============================================
   SEND MESSAGE FORM
   ============================================ */
.chatSendMessageForm {
    position: relative;
    background: white;
    border-top: 1px solid #E5E7EB;
    flex-shrink: 0;
}

/* Premium Gate Overlay */
.chatPremiumGate {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.chatPremiumGateContent {
    text-align: center;
    padding: 1rem;
}

.chatPremiumIcon {
    font-size: 2.5rem;
    color: #F59E0B;
    margin-bottom: 1rem;
}

.chatPremiumText {
    font-size: 1.5rem;
    color: #374151;
    margin: 0 0 0.5rem 0;
}

.chatPremiumUpgradeBtn {
    background: linear-gradient(135deg, #F59E0B 0%, #D97706 100%);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-size: 1.5rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
}

.chatPremiumUpgradeBtn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

/* Error Message Area */
.chatSendError {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: #FEF2F2;
    border-bottom: 1px solid #FCA5A5;
}

.chatSendErrorContent {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #B91C1C;
    font-size: 1.5rem;
}

.chatSendErrorText {
    text-align: left;
}

/*.chatSendErrorContent i {
    font-size: 1.25rem;
}*/

.chatSendErrorClose {
    background: none;
    border: none;
    color: #B91C1C;
    cursor: pointer;
    padding: 0.25rem;
    font-size: 1.5rem;
}

/* Message Input Area */
.chatSendInputWrapper {
    display: flex;
    align-items: flex-end;
    padding: 1rem;
    gap: 0.75rem;
}

.chatSendInput {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid #E5E7EB;
    border-radius: 12px;
    font-size: 1.6rem;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 120px;
    transition: all 0.2s ease;
}

.chatSendInput:focus {
    border-color: #1775FF;
    box-shadow: 0 0 0 3px rgba(23, 117, 255, 0.1);
}

.chatSendInput:disabled {
    background: #F9FAFB;
    cursor: not-allowed;
}

.chatSendButton {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #1775FF 0%, #0056D2 100%);
    color: white;
    font-size: 2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.chatSendButton:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(23, 117, 255, 0.3);
}

.chatSendButton:active:not(:disabled) {
    transform: scale(0.95);
}

.chatSendButton:disabled {
    background: #D1D5DB;
    cursor: not-allowed;
}

.chatSendButton i {
    margin-right: 0.25rem;
}

/* Character Counter */
.chatCharCounter {
    padding: 0 1rem 0.5rem 1rem;
    text-align: right;
}

.chatCharCountText {
    font-size: 0.75rem;
    color: #9CA3AF;
}

.chatCharCountText.chatCharCountWarning {
    color: #F59E0B;
}

.chatCharCountText.chatCharCountDanger {
    color: #EF4444;
}

/* ============================================
   UTILITY CLASSES
   ============================================ */
.chatHidden {
    display: none !important;
}

/* ============================================
   SCROLLBAR STYLING
   ============================================ */
.chatConversationsContainer::-webkit-scrollbar,
.chatMessagesContainer::-webkit-scrollbar {
    width: 6px;
}

.chatConversationsContainer::-webkit-scrollbar-track,
.chatMessagesContainer::-webkit-scrollbar-track {
    background: transparent;
}

.chatConversationsContainer::-webkit-scrollbar-thumb,
.chatMessagesContainer::-webkit-scrollbar-thumb {
    background: #D1D5DB;
    border-radius: 3px;
}

.chatConversationsContainer::-webkit-scrollbar-thumb:hover,
.chatMessagesContainer::-webkit-scrollbar-thumb:hover {
    background: #9CA3AF;
}

/* ============================================
   RESPONSIVE - MOBILE ADJUSTMENTS
   ============================================ */
@media (max-width: 768px) {
    .chatPanelHeader {
        padding: 0.875rem 1rem;
    }

    .chatPanelTitle {
        font-size: 1.75rem;
    }

    .chatBackButton {
        font-size: 1.75rem;
    }

    .chatMessagesHeaderName {
        font-size: 1.5rem;
    }

    .chatConversationTime {
        font-size: 1.2rem;
    }

    .chatConversationName {
        font-size: 1.25rem;
    }

    .chatConversationMessage {
        font-size: 1.25rem;
    }

    .chatMessageText {
        font-size: 1.3rem;
    }

    .chatMessageTime {
        font-size: 1.1rem;
    }

    .chatMessageStatus {
        font-size: 1.25rem;
    }

    .chatDateSeparatorText {
        font-size: 1.3rem;
    }

    .chatConversationBadge {
        font-size: 1.2rem;
    }

    .chatMessageBubble {
        max-width: 85%;
    }

    .chatSendErrorContent {
        font-size: 1.25rem;
    }

    .chatConversationCard {
        padding: 0.875rem;
    }

    .chatConversationAvatarImg {
        width: 44px;
        height: 44px;
    }

    .chatSendInput {
        font-size: 1.5rem;
    }

    .chatSendButton {
        font-size: 1.8rem;
    }

    .chatMessagesHeaderAvatar {
        width: 36px;
        height: 36px;
    }

    .chatSearchIcon {
        font-size: 1.15rem;
    }

    .chatSearchInput {
        font-size: 1.25rem;
        padding: 0.75rem 1rem 0.75rem 2.75rem;
    }

    .chatEmptyTitle {
        font-size: 1.4rem;
    }

    .chatEmptyText {
        font-size: 1rem;
    }

    .chatPremiumText {
        font-size: 1.25rem;
    }

    .chatPremiumUpgradeBtn {
        font-size: 1.25rem;
    }
}

/* ============================================
   MESSAGE DELETE FUNCTIONALITY
   Context Menu and Modal Dialog Styles
   ============================================ */

/* Context Menu */
.chatContextMenu {
    position: absolute;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 10002;
    min-width: 180px;
    overflow: hidden;
    animation: chatContextMenuFadeIn 0.15s ease;
}

@keyframes chatContextMenuFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.chatContextMenuItem {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.875rem 1rem;
    background: none;
    border: none;
    text-align: left;
    font-size: 1.4rem;
    color: #374151;
    cursor: pointer;
    transition: background 0.15s ease;
}

.chatContextMenuItem:hover {
    background: #F3F4F6;
}

.chatContextMenuItem i {
    font-size: 1.4rem;
    color: #EF4444;
    width: 18px;
    text-align: center;
}

.chatContextMenuItemText {
    flex: 1;
}

/* Modal Dialog */
.chatModalOverlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 10003;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem 3rem;
    animation: chatModalOverlayFadeIn 0.2s ease;
}

@keyframes chatModalOverlayFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.chatModal {
    background: white;
    border-radius: 12px;
    max-width: 400px;
    width: 100%;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    animation: chatModalSlideIn 0.2s ease;
}

@keyframes chatModalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chatModalHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1.5rem;
}

.chatModalTitle {
    font-size: 1.75rem;
    font-weight: 600;
    color: #111827;
    margin: 0;
}

.chatModalClose {
    background: none;
    border: none;
    color: #6B7280;
    font-size: 1.75rem;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    transition: background 0.15s ease;
}

.chatModalClose:hover {
    background: #F3F4F6;
}

.chatModalBody {
    padding: 0.5rem 1.5rem;
    text-align: left;
}

.chatModalText {
    font-size: 1.5rem;
    color: #374151;
    line-height: 1.6;
    margin: 0;
}

.chatModalFooter {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 0.5rem 1.5rem 1rem;
}

.chatModalButton {
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-size: 1.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.chatModalButtonSecondary {
    background: #F3F4F6;
    color: #374151;
}

.chatModalButtonSecondary:hover {
    background: #E5E7EB;
}

.chatModalButtonDanger {
    background: #EF4444;
    color: white;
}

.chatModalButtonDanger:hover {
    background: #DC2626;
}

.chatModalButton i {
    font-size: 1.4rem;
}

/* Prevent text selection during long-press */
.chatMessageBubble {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Re-enable text selection for message text (for copy-paste) */
.chatMessageText {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .chatContextMenu {
        min-width: 160px;
    }

    .chatContextMenuItem {
        font-size: 1.3rem;
        padding: 0.75rem 1rem;
    }

    .chatContextMenuItem i {
        font-size: 1.3rem;
    }

    .chatModalTitle {
        font-size: 1.5rem;
    }

    .chatModalText {
        font-size: 1.3rem;
    }

    .chatModalButton {
        font-size: 1.3rem;
        padding: 0.625rem 1.25rem;
    }

    .chatModalButton i {
        font-size: 1.2rem;
    }
}
