.messages-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 0;
    height: calc(100vh - var(--nav-height) - 2rem);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.messages-list {
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.messages-list-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    position: relative;
}

.messages-list-header input {
    font-size: 0.8125rem;
}

.search-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    z-index: 100;
    max-height: 240px;
    overflow-y: auto;
}

.search-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    color: var(--text-primary);
    transition: background 0.15s;
    text-decoration: none;
}

.search-dropdown-item:hover {
    background: var(--bg-card-hover);
}

.messages-conversations {
    flex: 1;
    overflow-y: auto;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    transition: background 0.2s;
    cursor: pointer;
}

.conversation-item:hover {
    background: var(--bg-card-hover);
}

.conversation-item.active {
    background: var(--accent-light);
}

.conversation-info {
    flex: 1;
    min-width: 0;
}

.conversation-name {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.125rem;
}

.conversation-preview {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-time {
    font-size: 0.6875rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.messages-main {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
}

.messages-main-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.messages-main-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.messages-thread {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    padding-bottom: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: 0;
}

.message-bubble {
    max-width: 70%;
    padding: 0.625rem 0.875rem;
    border-radius: var(--radius-lg);
    font-size: 0.875rem;
    line-height: 1.5;
    position: relative;
}

.message-bubble.mine {
    align-self: flex-end;
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message-bubble.theirs {
    align-self: flex-start;
    background: var(--bg-card-hover);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 0.6875rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    display: block;
}

.message-bubble.mine .message-time {
    color: rgba(255, 255, 255, 0.7);
}

.messages-input-area {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.messages-input-area input[type="text"] {
    flex: 1;
    min-width: 0;
}

.messages-input-area .attachment-upload-container {
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.messages-input-area .attachment-preview-list {
    flex: 0 0 100%;
    order: -1;
    margin-top: 0;
    margin-bottom: 0.5rem;
}

.messages-send-btn {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    padding: 0;
    background: var(--accent);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: background 0.15s;
}

.messages-send-btn:hover {
    background: var(--accent-hover);
}

.messages-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    gap: 0.5rem;
}

.messages-empty p {
    font-size: 0.875rem;
}

.messages-back-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.25rem;
    padding: 0.25rem;
    cursor: pointer;
    line-height: 1;
    margin-right: 0.25rem;
}

.messages-back-btn:hover {
    color: var(--accent);
}

@media (max-width: 768px) {
    .messages-layout {
        grid-template-columns: 1fr;
        height: auto;
        min-height: calc(100vh - var(--nav-height) - 2rem);
    }
    .messages-list {
        display: flex;
    }
    .messages-list.hide {
        display: none;
    }
    .messages-main.hide {
        display: none;
    }
    .messages-back-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}
