/* Messages Layout */
body {
    background-color: #f8fafc;
    min-height: 100vh;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    padding: 0;
    overflow: hidden; /* Prevent body scroll, handle in containers */
}

/* Navbar Overrides for Messages Page */
.navbar {
    position: relative !important; /* Override fixed positioning */
    background: white !important; /* Override transparent */
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    flex-shrink: 0;
}

.navbar .nav-brand {
    color: var(--primary-color) !important;
}

.navbar .logo-img {
    filter: none !important; /* Show original logo colors */
}

.navbar .add-ad-btn-nav {
    display: none !important;
}

/* Match .navbar.scrolled style from main.css */
.navbar .profile-trigger {
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
    padding: 5px 10px !important;
    background: transparent !important;
    border: none !important;
    border-radius: 30px !important;
    box-shadow: none !important;
    transition: background 0.2s !important;
}

.navbar .profile-trigger:hover {
    background: var(--bg-color) !important;
    border-color: transparent !important;
    box-shadow: none !important;
}

.navbar .profile-trigger .avatar {
    width: 40px !important;
    height: 40px !important;
    background: var(--primary-color) !important;
    color: white !important;
    border: none !important;
    box-shadow: none !important;
    margin: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 18px !important;
}

.navbar .profile-trigger .avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.navbar .profile-trigger .avatar i {
    font-size: 18px !important;
    color: white !important;
}

.navbar .profile-trigger .fa-chevron-down {
    font-size: 12px !important;
    color: var(--text-light) !important;
    margin-left: 0 !important;
    opacity: 1 !important;
}

.messages-container {
    flex: 1;
    display: flex;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    min-height: 0;
    /* height is handled by flex: 1 */
    background: white;
    box-shadow: 0 0 20px rgba(0,0,0,0.05);
    overflow: hidden;
}

/* Sidebar */
.conversations-sidebar {
    width: 350px;
    border-right: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    background: white;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid #e2e8f0;
}

.sidebar-header h2 {
    font-size: 1.5rem;
    color: #1e293b;
    margin-bottom: 10px;
}

.conversations-list {
    flex: 1;
    overflow-y: auto;
}

.conversation-item {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid #f1f5f9;
}

.conversation-item:hover {
    background: #f8fafc;
}

.conversation-item.active {
    background: #eff6ff; /* Light blue */
    border-left: 4px solid var(--primary-color);
}

.conversation-item .avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 15px;
    color: #64748b;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.conversation-info {
    flex: 1;
    min-width: 0; /* For text truncation */
}

.conversation-top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
}

.conversation-name {
    font-weight: 600;
    color: #1e293b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-time {
    font-size: 0.8rem;
    color: #94a3b8;
}

.conversation-preview {
    font-size: 0.9rem;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-preview.unread {
    color: #1e293b;
    font-weight: 600;
}

/* Main Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #f8fafc;
    position: relative;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #94a3b8;
    text-align: center;
}

.empty-state i {
    font-size: 4rem;
    margin-bottom: 20px;
    color: #cbd5e1;
}

.chat-interface {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    padding: 15px 20px;
    background: white;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-user-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.chat-header .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #64748b;
}

.user-details h3 {
    font-size: 1.1rem;
    color: #1e293b;
    margin: 0;
}

.user-details .status {
    font-size: 0.8rem;
    color: #22c55e; /* Green for online */
}

.messages-list {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.message-bubble {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 15px;
    position: relative;
    font-size: 0.95rem;
    line-height: 1.4;
}

.message-bubble.sent {
    align-self: flex-end;
    background: var(--primary-color);
    color: white;
    border-bottom-right-radius: 4px;
}

.message-bubble.received {
    align-self: flex-start;
    background: white;
    color: #1e293b;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
}

.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 5px;
    margin-top: 5px;
    font-size: 0.7rem;
    opacity: 0.8;
}

.message-status i {
    font-size: 0.7rem;
}

.chat-input-area {
    padding: 20px;
    background: white;
    border-top: 1px solid #e2e8f0;
}

#messageForm {
    display: flex;
    gap: 10px;
}

#messageInput {
    flex: 1;
    padding: 12px 20px;
    border: 1px solid #e2e8f0;
    border-radius: 25px;
    outline: none;
    transition: border-color 0.2s;
}

#messageInput:focus {
    border-color: var(--primary-color);
}

.send-btn {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.send-btn:hover {
    background: var(--primary-dark);
}

/* Ad Share Card Styles */
.ad-share-card {
    cursor: pointer;
    margin-top: 8px;
    background: rgba(0,0,0,0.05);
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    width: 220px; /* Fixed width */
    transition: transform 0.2s;
    border: 1px solid rgba(0,0,0,0.1);
    position: relative;
}

.ad-share-card:hover {
    transform: scale(1.02);
}

.ad-share-image {
    height: 320px; /* Tall image (Reel style) */
    background-size: cover;
    background-position: center;
    position: relative;
}

.ad-share-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: linear-gradient(to top, rgba(0,0,0,0.9), transparent);
    padding: 20px 12px 12px;
    color: white;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.ad-share-title {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.ad-share-price {
    font-weight: 700;
    font-size: 1.1rem;
    color: #fbbf24; /* Gold/Yellow for visibility */
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

/* Adjust bubble padding for cards */
.message-bubble:has(.ad-share-card) {
    padding: 8px;
    background: transparent;
    border: none;
    box-shadow: none;
    max-width: 100%; /* Allow card to define width */
    width: auto;
}

.message-bubble:has(.ad-share-card) .message-text {
    background: var(--primary-color);
    color: white;
    padding: 8px 12px;
    border-radius: 12px;
    margin-bottom: 5px;
    display: inline-block;
    max-width: 220px; /* Match card width */
}

.message-bubble.received:has(.ad-share-card) .message-text {
    background: white;
    color: #1e293b;
    border: 1px solid #e2e8f0;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .messages-container {
        height: auto;
        min-height: 0;
    }
    
    .conversations-sidebar {
        width: 100%;
        display: flex; /* Default show sidebar */
    }

    .chat-area {
        display: none; /* Hide chat area on mobile initially */
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 10;
    }

    .chat-area.active {
        display: flex;
    }

    .conversations-sidebar.hidden {
        display: none;
    }

    #closeChatMobile {
        display: block; /* Show back button on mobile */
    }

    .message-bubble {
        max-width: 85%;
    }

    .chat-input-area {
        padding: 12px;
    }

    #messageInput {
        padding: 10px 14px;
    }

    .ad-share-card {
        width: 100%;
        max-width: 260px;
    }

    .ad-share-image {
        height: 240px;
    }
}

@media (min-width: 769px) {
    #closeChatMobile {
        display: none;
    }
}
