/* ============================================
   MESSAGES VIEW
   ============================================ */

.messages-view {
    height: calc(100vh - 140px);
    background: var(--bg-secondary);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    display: none;
    /* Hidden by default */
}

/* Ensure messages view is visible when active (handled via inline style for now, but cleaner here) */
.messages-view.active {
    display: block !important;
}

.messages-container {
    display: flex;
    height: 100%;
}

/* Sidebar: Conversation List */
.messages-sidebar {
    width: 320px;
    border-right: 1px solid var(--border-color);
    background: var(--bg-card);
    display: flex;
    flex-direction: column;
}

.messages-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.messages-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
}

.new-msg-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent-color);
    color: white;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.new-msg-btn:hover {
    background: var(--accent-hover);
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
}

.conversation-item {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.2s;
}

.conversation-item:hover {
    background: var(--bg-hover);
}

.conversation-item.active {
    background: var(--bg-hover);
    border-left: 3px solid var(--accent-color);
}

.conv-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    overflow: hidden;
}

.conv-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.conv-info {
    flex: 1;
    min-width: 0;
}

.conv-top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.conv-name {
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-time {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.conv-last-msg {
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-last-msg.unread {
    font-weight: 600;
    color: var(--text-primary);
}

/* Chat Window */
.chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    position: relative;
}

.chat-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
}

.placeholder-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

.chat-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-card);
}

.back-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
}

.chat-user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message-bubble {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.4;
    position: relative;
    word-wrap: break-word;
}

.message-bubble.sent {
    align-self: flex-end;
    background: var(--accent-color);
    color: white;
    border-bottom-right-radius: 4px;
}

.message-bubble.received {
    align-self: flex-start;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 0.7rem;
    opacity: 0.7;
    margin-top: 4px;
    text-align: right;
    display: block;
}

.chat-input-area {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-card);
    display: flex;
    gap: 12px;
}

.chat-input-area input {
    flex: 1;
    padding: 10px 16px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    outline: none;
}

.chat-input-area input:focus {
    border-color: var(--accent-color);
}

.chat-input-area button {
    padding: 0 20px;
    border-radius: 20px;
    background: var(--accent-color);
    color: white;
    border: none;
    font-weight: 600;
    cursor: pointer;
}

.chat-input-area button:hover {
    background: var(--accent-hover);
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .messages-view {
        height: calc(100vh - 120px);
        margin: 0 -16px;
        /* Full width on mobile */
        border-radius: 0;
        border: none;
    }

    .messages-container {
        position: relative;
    }

    .messages-sidebar {
        width: 100%;
        border-right: none;
    }

    .chat-window {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        transform: translateX(100%);
        transition: transform 0.3s ease;
        z-index: 10;
    }

    .chat-window.active {
        transform: translateX(0);
    }

    .mobile-only {
        display: block;
    }
}

@media (min-width: 769px) {
    .mobile-only {
        display: none;
    }
}