﻿/* --- Cấu trúc Layout chính --- */
.chat-container {
    display: flex;
    height: 100vh; /* Chiều cao cố định bằng viewport */
    max-height: 100vh; /* Không cho vượt quá viewport */
    font-family: sans-serif;
    background-color: #f9fafb;
    position: relative;
    z-index: 10; /* Đảm bảo nằm trên footer */
    overflow: hidden; /* Chặn scroll của container chính */
}

/* --- Cột trái: Danh sách hội thoại --- */
.conversation-list {
    flex-basis: 33.333333%;
    max-width: 33.333333%; /* ✅ Fix tràn */
    flex-shrink: 0;
    border-right: 1px solid #e5e7eb;
    background-color: #ffffff;
    display: flex;
    flex-direction: column;
    height: 100vh; /* Chiều cao cố định */
    max-height: 100vh;
    position: relative;
    z-index: 11;
    overflow: hidden; /* ✅ Chặn tràn, scroll chỉ ở conversation-list-body */
}

.conversation-list-header {
    padding: 1rem;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0; /* Không co lại khi scroll */
}

    .conversation-list-header h2 {
        font-size: 1.25rem;
        font-weight: 700;
        margin: 0;
    }

.conversation-list-body {
    overflow-y: auto; /* Scroll độc lập cho danh sách conversation */
    overflow-x: hidden;
    flex-grow: 1;
    flex-shrink: 1;
    min-height: 0; /* Quan trọng: cho phép flex item co lại và scroll */
}

/* Scrollbar styling cho conversation list */
.conversation-list-body::-webkit-scrollbar {
    width: 6px;
}

.conversation-list-body::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.conversation-list-body::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.conversation-list-body::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

.conversation-item {
    display: flex;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid #e5e7eb;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.3s ease;
    will-change: transform;
    width: 100%; /* ✅ Full width trong container */
    box-sizing: border-box; /* ✅ Padding không làm tràn */
}

    .conversation-item:hover {
        background-color: #f9fafb;
    }

    .conversation-item.selected {
        background-color: #f5f3ff;
    }

    .conversation-item .avatar {
        width: 3rem; /* 48px */
        height: 3rem; /* 48px */
        border-radius: 9999px;
        background-color: #e0e0e0;
        margin-right: 0.75rem;
        flex-shrink: 0;
    }

        .conversation-item .avatar img {
            width: 100%;
            height: 100%;
            border-radius: 9999px;
            object-fit: cover;
        }

    .conversation-item .details {
        flex-grow: 1;
        overflow: hidden;
        min-width: 0; /* ✅ Cho phép text truncate đúng cách */
    }

        .conversation-item .details .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .conversation-item .details .name {
            font-weight: 700;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .conversation-item .details .last-message {
            color: #6b7280;
            font-size: 0.875rem;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

.unread-dot {
    width: 0.75rem; /* 12px */
    height: 0.75rem; /* 12px */
    background-color: #8b5cf6;
    border-radius: 9999px;
    flex-shrink: 0;
}

.badge-unread {
    background-color: #ef4444;
    color: #fff;
    border-radius: 9999px;
    padding: 0 .4rem;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1.25rem;
    min-width: 1.25rem;
    text-align: center;
}


/* --- Cột phải: Cửa sổ chat --- */
.chat-view {
    flex-basis: 66.666667%;
    max-width: 66.666667%; /* ✅ Fix tràn */
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    height: 100vh; /* Chiều cao cố định */
    max-height: 100vh;
    overflow: hidden; /* Chặn scroll, scroll chỉ ở messages-container */
    position: relative;
    z-index: 11;
}

.chat-placeholder {
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6b7280;
}

.chat-window {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background-color: #ffffff;
    height: 100%; /* Chiều cao 100% của parent */
    max-height: 93%;
    position: relative;
    z-index: 11;
    overflow: hidden; /* Chặn scroll ở chat-window level */
}

.chat-header {
    padding: 1rem;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    flex-shrink: 0; /* Không co lại khi scroll */
}

    .chat-header .name {
        font-size: 1.125rem;
        font-weight: 600;
    }

.product-context-banner {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    border-bottom: 1px solid #e5e7eb;
    background-color: #f9fafb;
    flex-shrink: 0; /* Không co lại khi scroll */
}

    .product-context-banner img {
        width: 3rem; /* 48px */
        height: 3rem; /* 48px */
        border-radius: 0.25rem;
        object-fit: cover;
        margin-right: 0.75rem;
    }

    .product-context-banner .product-name {
        font-weight: 600;
    }

.messages-container {
    flex-grow: 1;
    flex-shrink: 1;
    min-height: 0; /* Quan trọng: cho phép flex item co lại và scroll */
    overflow-y: auto; /* Scroll độc lập cho tin nhắn */
    overflow-x: hidden;
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

/* Scrollbar styling cho messages container */
.messages-container::-webkit-scrollbar {
    width: 8px;
}

.messages-container::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.messages-container::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

.message-row {
    display: flex;
    margin-bottom: 1rem;
}

    .message-row.me {
        justify-content: flex-end;
    }

    .message-row.them {
        justify-content: flex-start;
    }

.message-bubble {
    padding: 0.5rem 1rem;
    border-radius: 1rem;
    max-width: 100%;
    word-wrap: break-word;
    word-break: break-word;
    cursor: pointer;
    transition: background-color 0.1s ease;
}

    .message-bubble.me {
        background-color: #8b5cf6;
        color: white;
        border-bottom-right-radius: 0.25rem;
    }
    
    /* Ensure images in my messages don't inherit bubble background */
    .message-bubble.me img {
        background-color: transparent !important;
        background: none !important;
    }

    .message-bubble.them {
        background-color: #e5e7eb;
        color: #1f2937;
        border-bottom-left-radius: 0.25rem;
    }
    
    /* Ensure images in their messages don't inherit bubble background */
    .message-bubble.them img {
        background-color: transparent !important;
        background: none !important;
    }

.message-bubble:hover {
    filter: brightness(0.95);
}

.message-form {
    padding: 1rem;
    border-top: 1px solid #e5e7eb;
    background-color: #f9fafb;
    display: flex;
    align-items: center;
    flex-shrink: 0; /* Không co lại, luôn ở dưới cùng */
}

    .message-form input {
        flex-grow: 1;
        border: 1px solid #d1d5db;
        padding: 0.5rem 1rem;
        border-radius: 0.5rem;
        margin-right: 0.5rem;
    }

    .message-form button {
        border: none;
        background-color: #8b5cf6;
        color: white;
        padding: 0.5rem 1.5rem;
        border-radius: 0.5rem;
        cursor: pointer;
        transition: background-color 0.2s;
    }

        .message-form button:hover {
            background-color: #7c3aed;
        }

        .message-form button:disabled {
            background-color: #9ca3af;
            cursor: not-allowed;
        }

/* Attach icon button inside input bar */
.message-form .attach-btn {
    color: #111827; /* black-ish */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 36px;
    width: 36px;
    margin-right: 0.25rem;
}

/* Message bubble spacing for media */
.message-bubble img,
.message-bubble video {
    display: block;
    max-width: 260px; /* Giới hạn kích thước tối đa */
    width: auto;
    height: auto;
    background: transparent !important;
    border-radius: 8px;
    margin: 0;
    padding: 0;
    object-fit: contain;
}

/* Remove background from image containers */
.message-bubble img {
    background-color: transparent !important;
    box-shadow: none !important;
}

/* Ensure bubble container constrains media properly */
.message-bubble {
    overflow: hidden;
}

/* Link styling in messages */
.message-bubble.me a {
    color: white !important;
    text-decoration: underline;
}

.message-bubble.them a {
    color: #1f2937 !important;
    text-decoration: underline;
}

/* Remove background from any div containing media */
.message-bubble div:has(img),
.message-bubble div:has(video) {
    background: transparent !important;
    background-color: transparent !important;
}

/* Media elements should have no background */
.message-bubble video {
    background: transparent !important;
    background-color: transparent !important;
}

.hidden {
    display: none !important;
}

.conversation-item .details .product-topic {
    font-size: 0.8rem;
    color: #6c757d;
    margin: 2px 0 4px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.product-context-banner a {
    text-decoration: none; /* Bỏ gạch chân */
    color: inherit; /* Giữ màu chữ mặc định của phần tử cha */
}

/* --- Timestamp styling for messages --- */
.message-timestamp {
    font-size: 0.75rem; /* 12px */
    color: #6b7280; /* gray-500 */
    text-align: center;
    margin-top: 0.25rem; /* 4px */
    padding: 0.125rem 0.5rem; /* 2px 8px */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    user-select: none;
    cursor: default;
}

.message-timestamp.show {
    opacity: 1;
    visibility: visible;
}

.message-bubble-container {
    display: flex;
    flex-direction: column;
    max-width: 70%;
    word-wrap: break-word;
    overflow: hidden;
}

    .message-bubble-container.me {
        align-items: flex-end;
        width: -webkit-fill-available;
    }

    .message-bubble-container.them {
        align-items: flex-start;
        width: -webkit-fill-available;
    }

/* Ensure message bubble doesn't exceed container */
.message-bubble-container .message-bubble {
    max-width: 100%;
    box-sizing: border-box;
}


/* ==================== PAGE CHAT MEDIA FEATURES (prefix: page-chat-) ==================== */

/* Media action buttons row */
.page-chat-media-actions {
    display: flex;
    gap: 4px;
    padding: 8px 1rem 0;
    background: #f9fafb;
}

.page-chat-media-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: #8b5cf6;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.page-chat-media-btn:hover {
    background: rgba(139, 92, 246, 0.15);
    transform: scale(1.1);
}

.page-chat-media-btn svg {
    width: 20px;
    height: 20px;
}

.page-chat-gif-text {
    font-size: 11px;
    font-weight: 700;
    color: #8b5cf6;
}

/* Emoji button */
.page-chat-emoji-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: #fbbf24;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.page-chat-emoji-btn:hover {
    transform: scale(1.15);
}

.page-chat-emoji-btn svg {
    width: 20px;
    height: 20px;
}

/* Like button - emoji style */
.page-chat-like-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    border: none;
    background: transparent;
    font-size: 24px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    padding: 0;
    margin-left: 4px;
}

.page-chat-like-btn:hover {
    transform: scale(1.2);
    background: rgba(139, 92, 246, 0.1);
}

/* ==================== PAGE CHAT EMOJI PICKER (Messenger-style) ==================== */
.page-chat-emoji-picker {
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
    padding: 8px;
    max-height: 280px;
    display: flex;
    flex-direction: column;
}

.page-chat-emoji-search {
    margin-bottom: 8px;
    flex-shrink: 0;
}

.page-chat-emoji-search-input {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: #f9fafb;
    color: #1f2937;
    font-size: 13px;
    outline: none;
}

.page-chat-emoji-search-input:focus {
    background: #ffffff;
    border-color: #8b5cf6;
}

.page-chat-emoji-tabs {
    display: flex;
    gap: 2px;
    padding: 6px 0;
    border-bottom: 1px solid #e5e7eb;
    overflow-x: auto;
    flex-shrink: 0;
    margin-bottom: 8px;
}

.page-chat-emoji-tab {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border: none;
    background: transparent;
    border-radius: 8px;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.page-chat-emoji-tab:hover {
    background: rgba(139, 92, 246, 0.1);
}

.page-chat-emoji-tab.active {
    background: rgba(139, 92, 246, 0.2);
}

.page-chat-emoji-content {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.page-chat-emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
}

.page-chat-emoji-item {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.15s;
}

.page-chat-emoji-item:hover {
    background: rgba(139, 92, 246, 0.15);
    transform: scale(1.2);
}

.page-chat-emoji-empty {
    text-align: center;
    padding: 20px;
    color: #6b7280;
    font-size: 13px;
    grid-column: span 8;
}

.page-chat-emoji-content::-webkit-scrollbar {
    width: 6px;
}

.page-chat-emoji-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.page-chat-emoji-content::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.page-chat-emoji-tabs::-webkit-scrollbar {
    height: 4px;
}

.page-chat-emoji-tabs::-webkit-scrollbar-track {
    background: transparent;
}

.page-chat-emoji-tabs::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 2px;
}

/* ==================== PAGE CHAT STICKER PICKER ==================== */
.page-chat-sticker-picker {
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
    max-height: 280px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.page-chat-sticker-search {
    padding: 8px 12px;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.page-chat-sticker-input {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: #f9fafb;
    color: #1f2937;
    font-size: 13px;
    outline: none;
}

.page-chat-sticker-input:focus {
    background: #ffffff;
    border-color: #8b5cf6;
}

.page-chat-sticker-tabs {
    display: flex;
    gap: 2px;
    padding: 6px 8px;
    border-bottom: 1px solid #e5e7eb;
    overflow-x: auto;
    flex-shrink: 0;
}

.page-chat-sticker-tab {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border: none;
    background: transparent;
    border-radius: 8px;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.page-chat-sticker-tab:hover {
    background: rgba(139, 92, 246, 0.1);
}

.page-chat-sticker-tab.active {
    background: rgba(139, 92, 246, 0.2);
}

.page-chat-sticker-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    min-height: 0;
}

.page-chat-sticker-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
}

.page-chat-sticker-item {
    font-size: 28px;
    padding: 8px;
    text-align: center;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.15s;
}

.page-chat-sticker-item:hover {
    background: rgba(139, 92, 246, 0.15);
    transform: scale(1.15);
}

/* ==================== PAGE CHAT GIF PICKER ==================== */
.page-chat-gif-picker {
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
    padding: 8px;
    max-height: 280px;
    display: flex;
    flex-direction: column;
}

.page-chat-gif-search {
    margin-bottom: 8px;
    flex-shrink: 0;
}

.page-chat-gif-input {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: #f9fafb;
    color: #1f2937;
    font-size: 13px;
    outline: none;
}

.page-chat-gif-input:focus {
    background: #ffffff;
    border-color: #8b5cf6;
}

.page-chat-gif-container {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.page-chat-gif-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.page-chat-gif-item {
    width: 100%;
    height: 80px;
    object-fit: cover;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
}

.page-chat-gif-item:hover {
    transform: scale(1.05);
    box-shadow: 0 0 0 2px #8b5cf6;
}

.page-chat-gif-loading, .page-chat-gif-empty {
    text-align: center;
    padding: 20px;
    color: #6b7280;
    font-size: 13px;
    grid-column: span 3;
}

.page-chat-gif-loading svg {
    animation: page-chat-spin 1s linear infinite;
    margin-bottom: 8px;
}

@keyframes page-chat-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ==================== PAGE CHAT VOICE RECORDING UI ==================== */
.page-chat-recording-ui {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 1rem;
    background: #f9fafb;
    border-top: 1px solid #e5e7eb;
}

.page-chat-recording-ui.hidden {
    display: none;
}

.page-chat-rec-cancel {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.page-chat-rec-cancel:hover {
    background: rgba(239, 68, 68, 0.3);
    transform: scale(1.1);
}

.page-chat-rec-timer {
    flex: 1;
    text-align: center;
    font-size: 20px;
    font-weight: 600;
    color: #1f2937;
    font-family: monospace;
}

.page-chat-rec-stop {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: #ef4444;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    animation: page-chat-pulse 1.5s infinite;
}

@keyframes page-chat-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    50% { box-shadow: 0 0 0 12px rgba(239, 68, 68, 0); }
}

.page-chat-rec-stop:hover {
    transform: scale(1.05);
}

/* ==================== PAGE CHAT VOICE PREVIEW UI ==================== */
.page-chat-preview-ui {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 1rem;
    background: #f9fafb;
    border-top: 1px solid #e5e7eb;
}

.page-chat-preview-ui.hidden {
    display: none;
}

.page-chat-prev-cancel {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 50%;
    border: none;
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.page-chat-prev-cancel:hover {
    background: rgba(239, 68, 68, 0.3);
}

.page-chat-prev-play {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 50%;
    border: none;
    background: #8b5cf6;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.page-chat-prev-play:hover {
    background: #7c3aed;
}

.page-chat-waveform {
    flex: 1;
    height: 36px;
    min-width: 0;
    display: flex;
    align-items: center;
    padding: 0 12px;
    background: #e5e7eb;
    border-radius: 18px;
    overflow: hidden;
}

.page-chat-wave-bars {
    display: flex;
    align-items: center;
    gap: 2px;
    width: 100%;
    height: 28px;
}

.page-chat-wave-bar {
    width: 3px;
    min-width: 3px;
    background: rgba(139, 92, 246, 0.4);
    border-radius: 2px;
    flex-shrink: 0;
    transition: background 0.1s ease;
}

.page-chat-wave-bar.active {
    background: #8b5cf6;
}

.page-chat-prev-duration {
    font-size: 14px;
    color: #1f2937;
    font-family: monospace;
    min-width: 40px;
    flex-shrink: 0;
    text-align: center;
}

.page-chat-prev-send {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 50%;
    border: none;
    background: #8b5cf6;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.page-chat-prev-send:hover {
    background: #7c3aed;
    transform: scale(1.1);
}

/* Scrollbar styling for page chat pickers */
.page-chat-sticker-content::-webkit-scrollbar,
.page-chat-gif-container::-webkit-scrollbar,
.page-chat-emoji-picker::-webkit-scrollbar {
    width: 6px;
}

.page-chat-sticker-content::-webkit-scrollbar-track,
.page-chat-gif-container::-webkit-scrollbar-track,
.page-chat-emoji-picker::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.page-chat-sticker-content::-webkit-scrollbar-thumb,
.page-chat-gif-container::-webkit-scrollbar-thumb,
.page-chat-emoji-picker::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}


/* ==================== FIX AUDIO/VIDEO IN MESSAGE BUBBLE ==================== */
.message-bubble audio,
.message-bubble video {
    max-width: 100%;
    border-radius: 8px;
}

/* Voice message - remove bubble background when containing voice player */
.message-bubble:has(.voice-message-player) {
    padding: 0 !important;
    background: transparent !important;
}

.message-bubble .voice-message-player {
    display: flex !important;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #e5e7eb;
    border-radius: 20px;
    max-width: 240px;
    min-height: 40px;
    width: fit-content;
    box-sizing: border-box;
}

/* Voice player for receiver (them) - gray style */
.message-bubble.them .voice-message-player {
    background: #e5e7eb !important;
}

.message-bubble.them .voice-message-player .voice-play-btn {
    background: rgba(0, 0, 0, 0.1) !important;
    color: #1f2937 !important;
}

.message-bubble.them .voice-message-player .voice-duration-display {
    color: #6b7280 !important;
}

.message-bubble.them .voice-message-player .waveform-bar {
    background: rgba(0, 0, 0, 0.3) !important;
}

.message-bubble.them .voice-message-player .waveform-bar.active {
    background: #1f2937 !important;
}

/* Voice player for sender (me) - purple style */
.message-bubble.me .voice-message-player {
    background: #8b5cf6 !important;
}

.message-bubble.me .voice-message-player .voice-play-btn {
    background: rgba(255, 255, 255, 0.25) !important;
    color: white !important;
}

.message-bubble.me .voice-message-player .voice-play-btn:hover {
    background: rgba(255, 255, 255, 0.35) !important;
}

.message-bubble.me .voice-message-player .voice-play-btn svg {
    fill: white !important;
}

.message-bubble.me .voice-message-player .voice-duration-display {
    color: white !important;
}

.message-bubble.me .voice-message-player .waveform-bar {
    background: rgba(255, 255, 255, 0.5) !important;
}

.message-bubble.me .voice-message-player .waveform-bar.active {
    background: white !important;
}

/* Voice player components - scoped to voice-message-player to avoid conflicts */
.voice-message-player .voice-play-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.1);
    color: #1f2937;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.voice-message-player .voice-play-btn:hover {
    background: rgba(0, 0, 0, 0.15);
}

.voice-message-player .voice-waveform-display {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 1;
    height: 24px;
    min-width: 0;
}

/* Scope waveform-bar to voice-message-player to avoid conflict with floating-chat */
.voice-message-player .waveform-bar {
    width: 3px;
    min-width: 3px;
    min-height: 4px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 2px;
    transition: background 0.1s ease;
    flex-shrink: 0;
}

.voice-message-player .waveform-bar.active {
    background: #1f2937;
}

.voice-message-player .voice-duration-display {
    font-size: 12px;
    color: #6b7280;
    font-family: monospace;
    min-width: 35px;
    flex-shrink: 0;
    text-align: right;
}

/* Native audio element styling */
.message-bubble audio {
    display: block;
    max-width: 240px;
    width: 100%;
    height: 40px;
    border-radius: 20px;
}

/* Remove bubble background when only contains native audio */
.message-bubble:has(audio:only-child) {
    padding: 6px 8px;
    background: transparent !important;
}

/* Style native audio in me/them bubbles */
.message-bubble.me audio {
    filter: invert(1) hue-rotate(180deg);
}

.message-bubble.them audio {
    filter: none;
}

/* Ensure GIF images display properly */
.message-bubble img[alt="GIF"],
.message-bubble img[src*="giphy.com"],
.message-bubble img[src*="tenor.com"],
.message-bubble img[src*="media.giphy"] {
    max-width: 260px;
    border-radius: 8px;
    background: transparent !important;
}

/* Generic .gif URL - but exclude cloudinary audio/video */
.message-bubble img[src$=".gif"]:not([src*="cloudinary"]):not([src*="res.cloudinary"]) {
    max-width: 260px;
    border-radius: 8px;
    background: transparent !important;
}

/* Voice/Audio from Cloudinary rendered as img - limit height */
.message-bubble img[src*="cloudinary"][src*="video"],
.message-bubble img[src*="cloudinary"][src*="webm"],
.message-bubble img[src*="res.cloudinary"][src*="video"] {
    max-width: 240px;
    max-height: 40px;
    border-radius: 20px;
    object-fit: contain;
}

/* Video attachment size limit info */
.page-chat-video-limit {
    font-size: 11px;
    color: #6b7280;
    margin-top: 4px;
}


/* ==================== PAGE CHAT PRODUCT PICKER ==================== */
.page-chat-product-picker {
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
    padding: 0;
    height: 350px;
    max-height: 400px;
    min-height: 300px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
    margin-bottom: 8px;
}

.page-chat-product-header {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 16px 20px !important;
    border-bottom: 1px solid #e5e7eb !important;
    flex-shrink: 0 !important;
    background: linear-gradient(135deg, #f8f4ff 0%, #f3e8ff 100%) !important;
}

.page-chat-product-title {
    font-size: 18px !important;
    font-weight: 700 !important;
    color: #1f2937 !important;
    letter-spacing: -0.3px;
}

.page-chat-product-close {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: #666666;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.page-chat-product-close:hover {
    background: #f0f0f0;
    color: #333333;
}

/* Product Picker Tabs (for Provider chatting with Staff/Admin) */
.page-chat-product-tabs {
    display: flex;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.page-chat-product-tab {
    flex: 1;
    padding: 12px 16px;
    border: none;
    background: transparent;
    color: #6b7280;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
}

.page-chat-product-tab:hover {
    background: #f9fafb;
    color: #374151;
}

.page-chat-product-tab.active {
    color: #8b5cf6;
    border-bottom-color: #8b5cf6;
    background: #faf5ff;
}

.page-chat-product-search {
    padding: 8px 12px;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.page-chat-product-input {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 12px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    background: #f5f5f5;
    color: #333333;
    font-size: 13px;
    outline: none;
}

.page-chat-product-input:focus {
    background: #ffffff;
    border-color: #8b5cf6;
}

.page-chat-product-content {
    flex: 1;
    overflow-y: auto;
    min-height: 0; /* Important for flex child to allow shrinking and enable scroll */
    max-height: 220px; /* Ensure scrollable area has max height */
}

.page-chat-product-content::-webkit-scrollbar {
    width: 6px;
}

.page-chat-product-content::-webkit-scrollbar-thumb {
    background: #d0d0d0;
    border-radius: 3px;
}

.page-chat-product-content::-webkit-scrollbar-thumb:hover {
    background: #b0b0b0;
}

.page-chat-product-list {
    padding: 8px;
}

.page-chat-product-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
    border: 1px solid transparent;
}

.page-chat-product-item:hover {
    background: rgba(139, 92, 246, 0.08);
    border-color: rgba(139, 92, 246, 0.2);
}

.page-chat-product-image {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
    background: #f0f0f0;
}

.page-chat-product-info {
    flex: 1;
    min-width: 0;
}

.page-chat-product-name {
    font-size: 13px;
    font-weight: 600;
    color: #333333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.page-chat-product-details {
    font-size: 11px;
    color: #666666;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.page-chat-product-price {
    color: #8b5cf6;
    font-weight: 500;
}

.page-chat-product-category {
    color: #888888;
}

.page-chat-product-loading,
.page-chat-product-empty {
    text-align: center;
    padding: 30px 20px;
    color: #999999;
    font-size: 13px;
}

.page-chat-product-loading svg {
    animation: page-chat-spin 1s linear infinite;
    margin-bottom: 8px;
}

.page-chat-product-load-more {
    display: block;
    width: 100%;
    padding: 10px;
    border: 1px dashed #d0d0d0;
    border-radius: 8px;
    background: transparent;
    color: #8b5cf6;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 8px;
}

.page-chat-product-load-more:hover {
    background: rgba(139, 92, 246, 0.08);
    border-color: #8b5cf6;
}

/* Selected product indicator */
.page-chat-selected-product {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    margin-bottom: 8px;
    background: linear-gradient(135deg, #f8f4ff 0%, #f3e8ff 100%);
    border-radius: 8px;
    border: 1px solid #e9d5ff;
}

.page-chat-selected-image {
    width: 36px;
    height: 36px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
}

.page-chat-selected-info {
    flex: 1;
    min-width: 0;
}

.page-chat-selected-label {
    font-size: 10px;
    color: #7c3aed;
    font-weight: 500;
}

.page-chat-selected-name {
    font-size: 12px;
    font-weight: 600;
    color: #333333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.page-chat-selected-remove {
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: #999999;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.page-chat-selected-remove:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

/* Scrollbar for product picker */
.page-chat-product-content::-webkit-scrollbar {
    width: 6px;
}

.page-chat-product-content::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.page-chat-product-content::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}


/* Buy price styling - different color from rental price */
.page-chat-product-buy-price {
    color: #059669 !important;
    font-weight: 600;
}

.page-chat-product-buy-price::before {
    content: "Buy: ";
    font-weight: 400;
    color: #666666;
}

.page-chat-product-price:not(.page-chat-product-buy-price)::before {
    content: "Rent: ";
    font-weight: 400;
    color: #666666;
}
